What Really Happens When You Click Save: Salesforce Order of Execution
One click on Save can set off 20 steps on the server: flows, triggers, validation rules, duplicate checks, roll-ups and sharing, all inside one transaction. When automation behaves "randomly", it's almost always because two pieces ran in a different order than you expected.
In this post you won't just read the order of execution, you'll run it. Press Save on a sample Opportunity, change the scenario, and watch which steps fire, which get skipped and where the transaction can stop. Then test yourself with a quick game and a quiz.
The Save Simulator
Set up the scenario, then press Save. Click any step to read what happens there.
- Stage
- Negotiation
- Amount
- $120,000
- Status
- Unsaved changes
Press Save or click a step.
1. Before-save: fix the record itself, for free
Before-save flows run first (step 3), then before triggers (step 4), and only then do your custom validation rules run (step 5). That means validation rules see every value your before-save automation set. Changes made here don't need an extra DML statement, so this is the cheapest place to set fields on the same record.
trigger OpportunityTrigger on Opportunity (before insert, before update) {
for (Opportunity opp : Trigger.new) {
// No DML needed: the record hasn't been saved yet
if (opp.Amount > 100000) opp.Approval_Tier__c = 'Executive';
}
}2. Saved is not committed
At step 7 the record is written to the database but not committed. Everything after that, including after triggers, flows, roll-ups and sharing, still runs in the same transaction. If any of it throws an unhandled error, the whole save rolls back. Emails, queueable jobs, future methods and asynchronous flow paths wait until after the commit (step 20), so they never run for a save that failed.
3. The workflow re-fire trap
A workflow field update saves the record again and fires your before update and after update triggers one more time, even when the original operation was an insert. Static variables aren't reset between those runs, which is why recursion guards work and also why badly written ones skip logic. And Trigger.old in that second run still holds the values from before the user's change, not the workflow's.
Rebuild the Pipeline
Tap the cards in the order Salesforce runs them. Tap a placed card to send it back.
Predict the Outcome
Five scenarios that come up in real orgs and real interviews.
Cheat sheet: where should my logic go?
| You need to… | Use | Why |
|---|---|---|
| Set or default fields on the same record | Before-save flow / before trigger | Runs before validation, no extra DML |
| Create or update related records | After-save flow / after trigger | The record has an Id by now |
| Block bad data with a clear message | Validation rule | Sees values set by before-save logic |
| Call an external system or send email | Async path / Queueable | Runs only after a successful commit |
| Guarantee automation order | One trigger + handler; flow trigger order | Multiple triggers on one event have no set order |
Based on the Triggers and Order of Execution page in the Apex Developer Guide. In API version 53.0 and earlier, after-save record-triggered flows run after entitlement rules.
Automation colliding in your org?
Book a session with our architects to untangle your triggers and flows.