Sub topic 3
Where Flows Sit in the Order of Execution
Assume you understand Salesforce objects, Flow Builder elements, formulas, and database transactions. This chapter focuses on what happens during one record transaction.
Order of Execution
A before-save flow runs early, before Salesforce saves the triggering record. It is intended to change fields on that record. An after-save flow runs after the record is saved, so it can create related records, update other records, or call actions.
Bulk Behavior and Shared Limits
Salesforce can process many records in one transaction. Design every flow for bulk use:
- Avoid assuming that only one record triggered the flow.
- Minimize Get Records, Create Records, and Update Records elements.
- Collect records and perform one create or update operation where possible.
- Remember that flows and Apex in the same transaction share governor limits, such as query and database-operation limits.
A flow that works for one record can fail when a data load processes hundreds of records.
Preventing Recursion
An after-save flow that updates a record can trigger automation again. Use precise entry conditions and choose “only when a record is updated to meet the condition requirements” when appropriate. Compare $Record with $Record__Prior so the flow responds only to a real field change.
Asynchronous and Scheduled Paths
Use an asynchronous path when work can happen after the main transaction, such as an external callout or noncritical processing. Use a scheduled path when an action must occur at a future time. These paths run separately, so the original transaction may finish before they execute.
Fault Paths and Custom Errors
Connect fault paths to logging or notification logic. For user-facing validation, a Custom Error element can stop the transaction and explain what must be corrected. Handle expected failures explicitly instead of allowing an unclear system error.
Testing and Debugging
Use Flow Builder’s Debug tool with representative records. Test inserts, updates, unchanged values, bulk operations, and failure paths. An Apex test can verify the saved result and related records. Also inspect flow error emails and debug logs when Apex and flows share a transaction.
Working Alongside Apex and Other Flows
Document every automation that changes the same object or fields. Before-save flows, Apex triggers, workflow updates, after-save flows, and other automation can cause repeated saves. Prefer one clear owner for each business rule. If ordering matters, use the available flow trigger order and coordinate with the Apex team.
Exercise
Which flow type should set a field on the triggering record without updating a related record?
Show answer
A before-save flow optimized for Fast Field Updates.