NexBlazers Logo
NexBlazers Learn • Build • Grow
Architecture & Apex

What Really Happens When You Click Save: Salesforce Order of Execution

Written by NexBlazers Architecture Team November 19, 2026 10 min read Interactive

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.

Load & check
Steps 1–2
Before save
Steps 3–7
After save
Steps 8–15
Wrap-up & commit
Steps 16–20
Try it

The Save Simulator

Set up the scenario, then press Save. Click any step to read what happens there.

Opportunity
Acme – Renewal FY27
Stage
Negotiation
Amount
$120,000
Status
Unsaved changes
Where does the save come from?
    Step detail

    Press Save or click a step.

    Transaction log (simplified)
    // waiting for save…

    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.

    Architecture Note: If an object has two triggers for the same event, Salesforce doesn't guarantee which runs first. The same goes for Process Builder and workflow-launched flows at step 13. Use one trigger per object with a handler class, and record-triggered flows where you need a controlled order.
    Mini game

    Rebuild the Pipeline

    Tap the cards in the order Salesforce runs them. Tap a placed card to send it back.

    Cards
    Interview-ready

    Predict the Outcome

    Five scenarios that come up in real orgs and real interviews.

    Question 1 of 5 Score: 0

    Cheat sheet: where should my logic go?

    You need to…UseWhy
    Set or default fields on the same recordBefore-save flow / before triggerRuns before validation, no extra DML
    Create or update related recordsAfter-save flow / after triggerThe record has an Id by now
    Block bad data with a clear messageValidation ruleSees values set by before-save logic
    Call an external system or send emailAsync path / QueueableRuns only after a successful commit
    Guarantee automation orderOne trigger + handler; flow trigger orderMultiple 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.

    Book Architecture Review