Flow Name: Count the Staff and Member Representation¶
Last Updated: 2025-04-29 Source Code: Count_the_Staff_and_Member_Representation.flow-meta.xml
API Name: Count_the_Staff_and_Member_Representation Status: Active Type: Custom Trigger: Invoked as a subflow from other Partnership flows
Business Purpose¶
Maintains accurate counts of Member Representatives and Staff Liaisons on Partnership records by counting related AANP_Representation records. Acts as a reusable calculation engine triggered by create, update, and delete events.
Process Flow¶
- Receives Partnership ID, AANP Representation ID, and event action (Create/Update or Delete) as input parameters
- Retrieves Partnership and AANP Representation records
- Checks the Role field to determine if it's a Member Representative or Staff Liaison
- For Member Representatives:
- If Create/Update: Counts all Member Representative roles for the Partnership
- If Delete: Decrements current count by 1
- For Staff Liaisons:
- If Create/Update: Counts all Staff Liaison roles for the Partnership
- If Delete: Decrements current count by 1
- Updates Member_Representation_Count__c or Staff_Representation_Count__c on Partnership
📊 Click to view Process Flow Diagram
flowchart TD
Start([Start: Invoked as Subflow<br/>Inputs: aanPRepresentationId, partnershipId, eventAction]) --> GetPartnership[Get Partnership Record]
GetPartnership --> GetRepresentation[Get AANP Representation Record]
GetRepresentation --> CheckRecords{Records Found?}
CheckRecords -->|No| End([End])
CheckRecords -->|Member Representative| CheckAction1{Event Action?}
CheckRecords -->|Staff Liaisons| CheckAction2{Event Action?}
CheckAction1 -->|Create/Update| GetMemberReps[Get All Member Representatives:<br/>For this Partnership]
CheckAction1 -->|Delete| DecrementMR[Decrement Count:<br/>Member_Representation_Count - 1]
CheckAction2 -->|Create/Update| GetStaffLiaisons[Get All Staff Liaisons:<br/>For this Partnership]
CheckAction2 -->|Delete| DecrementSL[Decrement Count:<br/>Staff_Representation_Count - 1]
GetMemberReps --> CountMR[Count Records:<br/>MembershipRep_Count = record count]
GetStaffLiaisons --> CountSL[Count Records:<br/>staffLiaisonsCount = record count]
CountMR --> ValidateMR{Count Different<br/>from Current?}
CountSL --> ValidateSL{Count Different<br/>from Current?}
ValidateMR -->|Yes| AssignMR[Assign Partnership:<br/>Member_Representation_Count__c = new count]
ValidateMR -->|No| End
ValidateSL -->|Yes| AssignSL[Assign Partnership:<br/>Staff_Representation_Count__c = new count]
ValidateSL -->|No| End
DecrementMR --> UpdateMR[Update Partnership:<br/>Member_Representation_Count__c]
DecrementSL --> UpdateSL[Update Partnership:<br/>Staff_Representation_Count__c]
AssignMR --> UpdateMR
AssignSL --> UpdateSL
UpdateMR --> End
UpdateSL --> End
style Start fill:#e1f5ff
style GetPartnership fill:#f0e1ff
style GetRepresentation fill:#f0e1ff
style GetMemberReps fill:#f0e1ff
style GetStaffLiaisons fill:#f0e1ff
style CheckRecords fill:#fff4e1
style CheckAction1 fill:#fff4e1
style CheckAction2 fill:#fff4e1
style ValidateMR fill:#fff4e1
style ValidateSL fill:#fff4e1
style CountMR fill:#e1ffe1
style CountSL fill:#e1ffe1
style DecrementMR fill:#e1ffe1
style DecrementSL fill:#e1ffe1
style AssignMR fill:#e1ffe1
style AssignSL fill:#e1ffe1
style UpdateMR fill:#ffe1e1
style UpdateSL fill:#ffe1e1
style End fill:#e1f5ff
Key Business Rules¶
- Operates on two role types: "Member Representative" and "Staff Liaisons"
- Create/Update actions perform full recounts from database
- Delete actions decrement existing counts by 1
- Validates records exist before processing
- Only updates counts when values have changed
Dependencies¶
- Objects: Partnership__c, AANP_Representation__c (custom objects)
- Fields: Role__c, Partnership__c, Member_Representation_Count__c, Staff_Representation_Count__c
- Calling Flows: Update_Partnership_on_Create_Update, Update_Partnership_on_Delete
- Input Variables: partnershipId, aanPRepresentationId, eventAction
Changes¶
No Pull Request references found in flow description.
⚠️ Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
- Missing Error Handling: No fault connectors configured - failures will be silent
- Null Check Missing: Does not verify Partnership or AANP Representation records exist before processing
- Race Condition Risk: Multiple simultaneous creates/deletes could cause inaccurate counts
HIGH - Address Soon After Go-Live¶
- Performance: Full recounts on every Create/Update could impact performance with large datasets
- Inconsistent Logic: Delete uses decrement while Create/Update uses full recount - could lead to drift
- No Validation: Doesn't validate that Role field contains expected values
MEDIUM - Future Enhancement¶
- Consistency Check: Add scheduled job to verify counts match actual records
- Bulkification: Optimize for bulk operations rather than individual record processing
- Logging: Add error logging for troubleshooting count discrepancies
LOW - Monitor¶
- Count Accuracy: Monitor for scenarios where counts don't match actual related records
- Performance: Watch for slow performance when Partnerships have many representations
Maintenance Notes¶
Complexity: Medium - Complex logic with multiple decision points and loops Review Schedule: Monthly review of count accuracy recommended Dependencies: Core calculation engine for Partnership representation tracking - changes affect multiple flows