Sub topic 13
Where flows run in the order of execution
This chapter assumes you know record-triggered flows, the difference between before-save and after-save flows, and basic Apex trigger behavior. Order of execution is the sequence Salesforce follows when it saves a record. It decides which automation sees which values, so it matters when you replace Workflow Rules and Process Builder.
The sequence that matters for migration
Salesforce runs these steps for a record save. The list is simplified to the steps that affect a migration.
- System validation and loading of the original record.
- Before-save record-triggered flows run.
- Before Apex triggers run.
- Custom validation rules and duplicate rules run.
- The record is saved to the database but not committed.
- After Apex triggers run.
- Assignment rules, auto-response rules, and escalation rules run.
- Workflow Rules run, and their field updates can re-fire before and after triggers once.
- After-save record-triggered flows run.
- Roll-up summary fields and other cross-object updates are calculated.
- The transaction commits.
What changes when you migrate
Before-save flows run before validation rules. A Workflow Rule field update ran after validation. A before-save flow can therefore set a value that a validation rule then checks. Check your validation rules after migration, because a rule that once failed on a raw user value may now see the flow's value.
After-save flows run after Workflow Rules and after after-triggers. Process Builder processes also ran as after-save automation, so a migrated after-save flow sits in about the same place.
Workflow field updates had a side effect. They re-ran before and after triggers, and the record kept its changes. A before-save flow does not do this, because it changes the record in memory before the save. If an Apex trigger relied on the re-run, test that behavior after the move.
Mixed automation during cutover
While you migrate, an object can have a Workflow Rule, a process, and a flow doing the same job. Each one fires on its own, so you can get duplicate emails, tasks, or updates. Deactivate the old automation as you activate its replacement.
An after-save flow that updates the triggering record starts a second save. That save runs the order of execution again, including your triggers and flows, with limits shared across the transaction. This is why bulk safety and recursion get their own chapter. For now, prefer a before-save flow when you only update fields on the triggering record.
Exercise
A Workflow Rule field update set Status to "Escalated". A validation rule requires an Escalation Reason whenever Status is "Escalated". After you replace the rule with a before-save flow, users report new validation errors. Why?
Show answer
The before-save flow runs before validation rules, so the rule now sees the flow's "Escalated" value and requires a reason. The Workflow Rule update ran after validation, so the check never saw the value. Fix it by having the flow also set the reason, by adjusting the validation rule, or by moving the logic to an after-save flow if the original timing must be kept.