Flow Name: Update Buyer Group Member On Create¶
Last Updated: 2025-10-22 Source Code: https://github.com/AANP-IT/I2C.Salesforce.Metadata/blob/STAGING/force-app/main/default/flows/Update_Buyer_Group_Member_On_Create.flow-meta.xml
API Name: Update_Buyer_Group_Member_On_Create Status: Active Type: Custom Trigger: After BuyerGroupMember record is created
Business Purpose¶
This flow maintains a consolidated list of buyer group memberships on Account records by updating the BuyerGroupIds__c field when new BuyerGroupMember records are created. This provides a quick reference field for buyer group associations without requiring complex relationship queries.
Process Flow¶
- BuyerGroupMember Created: New buyer group membership is created
- Lookup Account: Retrieves the related Account record using BuyerId
- Validate Account Found: Checks if account exists before proceeding
- Clear Existing List: Resets the BuyerGroupIds__c field to empty
- Query All Memberships: Retrieves all BuyerGroupMember records for this account
- Loop Through Memberships: Iterates through each membership and collects buyer group IDs
- Build Comma-Separated List: Concatenates all buyer group IDs with commas
- Update Account: Saves the updated BuyerGroupIds__c field to the account record
📊 Click to view Process Flow Diagram
flowchart TD
Start([Start: BuyerGroupMember Created]) --> Lookup[Lookup Related Account]
Lookup --> Found{Account<br/>Found?}
Found -->|No| End([End])
Found -->|Yes| Clear[Clear BuyerGroupIds Field]
Clear --> QueryAll[Query All BuyerGroupMembers<br/>for Account]
QueryAll --> Loop[Loop Through All Memberships]
Loop --> Build[Build Comma-Separated<br/>ID List]
Build --> Update[Update Account<br/>BuyerGroupIds Field]
Update --> End
style Start fill:#e1f5ff
style Lookup fill:#f0e1ff
style Found fill:#fff4e1
style Clear fill:#e1ffe1
style QueryAll fill:#f0e1ff
style Loop fill:#e1ffe1
style Build fill:#e1ffe1
style Update fill:#ffe1e1
style End fill:#e1f5ff
Key Business Rules¶
- Rebuilds entire buyer group ID list for the account (not incremental)
- Stores buyer group IDs as comma-separated string in BuyerGroupIds__c field
- Only updates account if buyer group IDs are found
- Provides denormalized data for faster access without relationship queries
- Runs after BuyerGroupMember record is saved
Dependencies¶
- Objects: BuyerGroupMember, Account
- Fields:
- BuyerGroupMember: BuyerId, BuyerGroupId
- Account: BuyerGroupIds__c (text field for comma-separated list)
- Relationships: BuyerGroupMember.BuyerId → Account.Id
Changes¶
No specific pull requests or changes documented in flow metadata.
⚠️ Pre-Go-Live Concerns¶
CRITICAL - Fix Before Go-Live¶
None identified.
HIGH - Address Soon After Go-Live¶
- No error handling: If account lookup fails or update fails, process fails silently
- Performance concern: Full list rebuild on every new membership is inefficient
- Field length limit: BuyerGroupIds__c text field could exceed limits with many buyer groups
MEDIUM - Future Enhancement¶
- Consider incremental approach (append new ID instead of rebuilding entire list)
- Add error handling and logging for troubleshooting
- Monitor BuyerGroupIds__c field length usage
- Consider using Set collection to prevent duplicate IDs
LOW - Monitor¶
- Test with accounts having many buyer group memberships (20+ groups)
- Verify field length is adequate for expected number of buyer groups
- Consider alternative storage (Custom Metadata or junction object) if performance becomes issue
Maintenance Notes¶
- Complexity: Medium - uses queries, loops, and string concatenation
- Review Schedule: When buyer group processes change or performance issues arise
- Testing Focus: Test with accounts having 0, 1, 5, 10, and 20+ buyer group memberships
- Performance Note: Each new buyer group membership triggers full list rebuild for that account