Skip to content

Flow Name: Account Team Member: to calculate Partnership fields (before delete)

Last Updated: 2024-11-14 Source Code: Account_Team_Member_On_Delete.flow-meta.xml

API Name: Account_Team_Member_On_Delete Status: Active Type: Custom Trigger: Before delete of AccountTeamMember records

Business Purpose

This flow maintains data integrity on Partnership records by triggering recalculation of partnership representation counts when Account Team Members are deleted. It ensures that Partnership objects accurately reflect current staff liaisons and member representation statistics by toggling calculation flags.

Process Flow

  1. Get Partnerships: Queries Partnership__c records where Staff_Liaisons__c equals the deleted Account Team Member's AccountId
  2. Check Partnerships Exist: Verifies partnerships are found before proceeding
  3. Loop Through Partnerships: Iterates through each related partnership record
  4. Toggle Calculation Flag: For each partnership, checks the current value of Calculate_count_on_AT_delete__c field and flips it (false becomes true, true becomes false)
  5. Build Update List: Adds modified partnership records to a collection for bulk update
  6. Update Partnerships: Performs bulk update of all modified partnership records
📊 Click to view Process Flow Diagram
flowchart TD
    Start([Start: AccountTeamMember<br/>Before Delete Trigger]) --> GetPartner[Get Partnership Records<br/>where Staff_Liaisons__c<br/>= AccountId]

    GetPartner --> HasPartner{Partnerships<br/>Found?}

    HasPartner -->|No| End([End])
    HasPartner -->|Yes| Loop[Loop Through Each<br/>Partnership Record]

    Loop --> Toggle[Toggle Calculate_count_on_AT_delete__c:<br/>• If TRUE → Set FALSE<br/>• If FALSE → Set TRUE]

    Toggle --> AddToCollection[Add Modified Partnership<br/>to Update Collection]

    AddToCollection --> MoreRecords{More<br/>Partnerships?}

    MoreRecords -->|Yes| Loop
    MoreRecords -->|No| BulkUpdate[Bulk Update All<br/>Partnership Records]

    BulkUpdate --> End

    style Start fill:#e1f5ff
    style GetPartner fill:#f0e1ff
    style HasPartner fill:#fff4e1
    style Loop fill:#e1ffe1
    style Toggle fill:#ffe1e1
    style AddToCollection fill:#e1ffe1
    style MoreRecords fill:#fff4e1
    style BulkUpdate fill:#ffe1e1
    style End fill:#e1f5ff

Key Business Rules

  • Only partnerships where Staff_Liaisons__c matches the deleted team member's AccountId are affected
  • The Calculate_count_on_AT_delete__c field is toggled to trigger downstream calculations
  • Updates are performed in bulk to maintain efficiency
  • Process only executes if partnerships exist for the account

Dependencies

  • Partnership__c custom object and its Calculate_count_on_AT_delete__c field
  • AccountTeamMember standard object
  • Related flow "Count the Staff and Member Representation" for actual count calculations
  • Account object (referenced through AccountTeamMember.AccountId)

⚠️ Pre-Go-Live Concerns

CRITICAL - Fix Before Go-Live

  • Validation Required: No error handling if Partnership updates fail, which could leave data in inconsistent state
  • Bulk Limits: No governor limit handling for large numbers of partnerships per account

HIGH - Address Soon After Go-Live

  • Performance Optimization: Each partnership update triggers additional flows, potentially causing performance issues with many partnerships
  • Logging Gap: No audit trail of which partnerships were updated or why calculations were triggered

MEDIUM - Future Enhancement

  • Logic Clarity: The toggle mechanism (flip true/false) is not intuitive and could be simplified
  • Conditional Processing: Could check if calculation is actually needed before updating

LOW - Monitor

  • Documentation: Field name suggests delete-specific logic but flow runs for all team member deletions
  • Naming Convention: Variable names could be more descriptive (partnershipRecord vs currentPartnership)

Maintenance Notes

Complexity: Medium - Straightforward logic but depends on external calculation flows. Review quarterly as part of partnership data integrity checks. Monitor for performance impacts when accounts have many partnerships.