Flow Name: Account Contact Relationship after insert/update¶
Last Updated: 2024-11-14 Source Code: Account_Contact_Relationship_after_insert_update.flow-meta.xml
API Name: Account_Contact_Relationship_after_insert_update Status: Active Type: Custom Trigger: AccountContactRelation creation/update (after save)
Business Purpose¶
Maintains accurate Company Administrator flags on Person Accounts by checking all AccountContactRelationships for a contact to determine if any relationship includes the "Company Administrator" role.
Process Flow¶
- Triggers on AccountContactRelation create/update
- Retrieves all other AccountContactRelations for the same ContactId (excluding current record)
- Loops through relationships to check if any contain "Company Administrator" role
- Sets boolean variable if Company Administrator role found
- Compares current Account Company Admin status with calculated status:
- Set to True: If admin role found but account flag is false
- Set to False: If no admin role found but account flag is true
- Updates Account Is_Company_Admin__c field accordingly
📊 Click to view Process Flow Diagram
flowchart TD
Start([Start: AccountContactRelation<br/>Create/Update After Save]) --> GetAll[Get All AccountContactRelations<br/>for Same ContactId<br/>excluding current record]
GetAll --> Loop[Loop Through Relationships:<br/>Check for Company Admin Role]
Loop --> DetectAdmin{Company Admin<br/>Role Found?}
DetectAdmin -->|Yes| SetVar[Set IsAdmin Variable = TRUE]
DetectAdmin -->|No| Continue[Continue Loop]
SetVar --> Compare{Account Status<br/>Matches Calculated?}
Continue --> Compare
Compare -->|Admin Found & Account Not Admin| SetTrue[Update Account:<br/>Is_Company_Admin__c = TRUE]
Compare -->|Admin Not Found & Account Is Admin| SetFalse[Update Account:<br/>Is_Company_Admin__c = FALSE]
Compare -->|Status Matches| End([End])
SetTrue --> End
SetFalse --> End
style Start fill:#e1f5ff
style GetAll fill:#f0e1ff
style Loop fill:#e1ffe1
style DetectAdmin fill:#fff4e1
style SetVar fill:#ffe1e1
style Continue fill:#e1ffe1
style Compare fill:#fff4e1
style SetTrue fill:#ffe1e1
style SetFalse fill:#ffe1e1
style End fill:#e1f5ff
Key Business Rules¶
- Evaluates ALL relationships for a contact, not just the current one
- Company Administrator role detection using both formula and loop logic
- Only updates account when there's a mismatch between actual and current status
- Uses dual detection methods (formula + variable assignment) for reliability
Dependencies¶
- AccountContactRelation with Roles field containing "Company Administrator"
- Account object with Is_Company_Admin__c checkbox field
- Person Account architecture linking Contact to Account
⚠️ Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
- No error handling for account update failures
- Redundant logic using both formula and variable assignment could cause inconsistencies
- Missing validation that account update succeeded
HIGH - Address Soon After Go-Live¶
- Complex dual-detection logic is unnecessarily complicated
- No bulkification considerations for mass relationship changes
- Potential race conditions with concurrent relationship updates
MEDIUM - Future Enhancement¶
- Simplify to use either formula OR variable logic, not both
- Add error handling and retry logic for account updates
- Consider batch processing for bulk operations
LOW - Monitor¶
- Performance with users having many account relationships
- Accuracy of Company Administrator detection
Maintenance Notes¶
Moderate complexity flow with redundant logic patterns. The dual detection approach suggests uncertainty about the most reliable method. Recommend simplifying and standardizing the detection logic.