Salesforce Record-Triggered Flow for Cross-Object Updates: Declarative Alternative to Apex Triggers
Replace Apex triggers with Record-Triggered After Save Flows for cross-object updates. Worked example: Opportunity Close Won updates parent Account rollups. Covers entry conditions, fault paths, governor limits, recursion prevention, and deployment verification.
30 Sept 2025, 10:21 UTC

The Problem and the Takeaway
You need to update a parent Account when an Opportunity closes won — without writing Apex. Use a Record‑Triggered Flow set to run After Save. After Save flows can query and update any related record via Get Records and Update Records elements, replacing the most common cross‑object trigger use cases. Before Save flows cannot do this; they only modify the triggering record ($Record) without DML.
How After Save Flows Work
An After Save flow runs after the triggering record is committed. It executes in the Automated Process user context by default, which respects sharing rules and field‑level security of that user (who has no role). If elevated access is needed, use Run As to specify a specific user.
The flow interview is bulkified automatically: Salesforce batches up to 200 triggering records per interview. Each interview consumes SOQL and DML limits (100 queries, 150 DML statements per transaction) and counts toward the org limit of 2,000 flow interviews per 24‑hour period.
Worked Example: Opportunity Close Won → Account Rollup
Goal: When an Opportunity moves to Closed Won for the first time, set the parent Account's Last_Won_Date__c to now and increment Total_Won_Amount__c by the Opportunity Amount.
Flow Configuration
- Create the flow: Setup → Flows → New Flow → Record‑Triggered Flow.
- Object: Opportunity.
- Trigger: Record Updated.
- Entry Conditions: IsWon Equals True AND PriorValue(IsWon) Equals False.
- Run As: Automated Process (default) or a specific integration user if sharing rules block access.
- Add Get Records:
- Label: Get Parent Account
- Object: Account
- Filter: Id Equals $Record.AccountId
- Fields: Id, Total_Won_Amount__c
- Store: First record only → {!Get_Parent_Account}
- Add Update Records:
- Label: Update Account Rollups
- Use the record from Get Records: {!Get_Parent_Account}
- Set fields:
Last_Won_Date__c = $Flow.CurrentDateTimeTotal_Won_Amount__c = $Record.Amount + {!Get_Parent_Account.Total_Won_Amount__c}
- Fault Path: Add a fault connector to an Action (Send Email) or Create Records (Error_Log__c) to capture failures without rolling back the Opportunity save.
- Save and Activate.
Why This Entry Condition Matters
Using PriorValue(IsWon) ensures the flow only runs on the transition to Won, not on every edit of an already‑Won Opportunity. Without it, every Amount change on a Won Opportunity would re‑trigger the rollup, inflating the total incorrectly.
Governor Limits and Bulk Behavior
| Limit | Value | Notes |
|---|---|---|
| Flow interviews per 24h | 2,000 per org | Exceeding fails silently for subsequent records. Monitor in Setup → Flows → Paused and Failed Flow Interviews. |
| SOQL queries per transaction | 100 | Each Get Records counts as one query. |
| DML statements per transaction | 150 | Each Update Records counts as one DML. |
| Batch size | Up to 200 records | One interview processes a batch; limits apply per interview. |
If you process 500 Opportunities in a single data load, Salesforce creates three interviews (200, 200, 100). Each interview gets its own limit bucket.
Common Mistakes and How to Avoid Them
1. Recursion Between Objects
A second flow on Account that updates Opportunity can create an infinite loop. Prevent it by adding entry conditions that check $Record__Prior values on the target object. Example: on Account flow, only run when Total_Won_Amount__c actually changes.
2. Automated Process User Lacks Role
Sharing rules based on role hierarchy do not apply to the Automated Process user. If the Account is private and the running user has no access, the Get Records returns null and the Update fails. Fix: set Run As to a user with appropriate sharing access, or adjust organization‑wide defaults.
3. Formula Fields Not Recalculated Before After Save
Formula fields on the triggering object reflect the old value when the After Save flow runs. If you need the new formula value, either requery the record in a Get Records element or move the logic to a Before Save flow (which can only update $Record).
4. Master‑Detail Child Records Locked During Parent Approval
Flows on OpportunityLineItem (or other detail records) that try to update the parent Opportunity will fail if the parent is locked in an approval process. The error surfaces as a DML exception on the Update Records element.
Error Handling: Fault Paths vs. Unhandled Faults
An unhandled fault in an After Save flow rolls back the entire transaction, including the original Opportunity save. Always add a fault path on the Update Records element. A minimal fault handler:
Fault Connector → Action: Send Email
To: {!$User.Email}
Subject: 'Flow Failed: Update Account Rollups'
Body: 'Record ID: {!$Record.Id}
Error: {!$Flow.FaultMessage}'
Alternatively, create an Error_Log__c record with the fault details for later review.
Deployment and Verification Checklist
- Build in sandbox. Create the flow, custom fields (Last_Won_Date__c, Total_Won_Amount__c on Account), and test data.
- Debug log: Setup → Debug Logs → New → Traced Entity: Automated Process. Run the flow by closing an Opportunity. Inspect SOQL/DML counts and interview duration.
- Limit monitoring: Setup → System Overview → Flow Interviews (24h). Confirm interview count increments per batch of 200.
- Recursion test: Add a second flow on Account that updates Opportunity. Verify entry conditions prevent infinite loops.
- Deploy via Change Set: Include Flow, FlowDefinition, and any custom fields. Validate in target org before activating.
Practical Verification Steps
- Create an Opportunity with an Account, Amount = 50000.
- Change Stage to Closed Won.
- Refresh the Account detail page. Verify:
- Last_Won_Date__c equals the close timestamp (within seconds).
- Total_Won_Amount__c increased by 50000.
- Edit the same Opportunity (change Description only). Confirm Account fields do not change again.
- Run a data load of 250 Opportunities closing won simultaneously. Check that three flow interviews appear in Paused and Failed Flow Interviews (none failed) and Account totals reflect all 250.
When to Still Use Apex
- Complex logic requiring loops, maps, or multiple related‑object updates in a single transaction that exceed flow element limits.
- Need to call external services (callouts) — flows support callouts only via invocable Apex.
- Performance‑critical bulk operations where you need fine‑grained control over query and DML placement.
For the vast majority of cross‑object field updates — rollups, status propagation, date stamping — Record‑Triggered After Save Flow is the supported, maintainable, and limit‑aware choice.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.