On this page
- What is a Salesforce flow race condition?
- Why does the order of execution matter?
- Why doesn't Salesforce warn you?
- How do I detect race conditions, step by step?
- How do I fix a race condition?
- Which tools help detect race conditions?
- How do I stop new race conditions?
- How can Clientell AI help?
- Sources
- Common questions about Salesforce flow race conditions
To detect a Salesforce flow race condition, list every automation that writes the same field on an object. Any field with two or more writers is a suspect. The steps below show how to build that list, rank it and fix it.
Clientell AI, the AI Salesforce admin, maps which flows, triggers and rules write each field, and drafts the fix. Start with the read-only Salesforce flow audit.
What is a Salesforce flow race condition?
A Salesforce race condition is two or more automations that write the same field in one save. The final value depends on which one runs last. Admins call it a race because the result looks random to users.
Here is an illustrative example. A record-triggered flow sets Opportunity.ForecastCategoryName to Commit when Stage is Negotiation. An Apex trigger, added later for a quoting tool, sets the same field from the quote status. A sales manager sees the forecast change after an unrelated edit. Nobody can reproduce it on demand.
Most of these bugs are not truly random. They come from the order of execution, which few people check.
Why does the order of execution matter?
Salesforce runs automation types in a set order on each save (Apex Developer Guide: Order of Execution). In short:
- Before-save record-triggered flows.
- Before triggers.
- Validation rules and duplicate rules.
- The record saves, but does not commit yet.
- After triggers.
- Assignment rules, auto-response rules, then workflow rules. A workflow field update fires the before and after update triggers one more time.
- After-save record-triggered flows and processes.
- Roll-up summaries, sharing, then the commit.
This order explains most "random" values:
Swipe sideways to see all columns
| Pair that writes one field | Who wins | Why |
|---|---|---|
| Before-save flow and before trigger | The trigger | Before triggers run after before-save flows |
| After trigger and after-save flow | Can flip back and forth | The flow runs later, and its update starts a new save that runs the triggers again |
| Workflow field update and trigger | Both, twice | The field update re-fires update triggers |
| Two triggers on one object | No fixed winner | Salesforce does not guarantee trigger order |
| Two flows with no Trigger Order | Hard to predict | Set Trigger Order to make it fixed |
Two triggers on the same object are the classic true race. Salesforce says the order of several triggers for the same event is not guaranteed (Apex Developer Guide: Triggers).
Flows have a fix. A record-triggered flow takes a Trigger Order from 1 to 2,000. Flows with the same value run in alphabetical order of API name (Salesforce Help: Flow Trigger Order). A rename can then change which flow wins.
Why doesn't Salesforce warn you?
Each automation lives on its own Setup page. Flows, triggers, workflow rules and processes each have a separate list. No page shows every writer of one field.
Each automation can be correct on its own. The bug is the mix. A correct flow plus a correct trigger can still give a wrong value.
How do I detect race conditions, step by step?
Step 1: List every automation on the object
For each object you audit, such as Opportunity, collect:
- Flows: open Setup > Process Automation > Flows, or use Flow Trigger Explorer to see every record-triggered flow per object and trigger (Trailhead: Flow Trigger Explorer).
- Apex triggers: open Setup > Object Manager > Opportunity > Triggers.
- Workflow rules: open Setup > Process Automation > Workflow Rules and filter by object. Salesforce ended support for Workflow Rules and Process Builder on 31-12-2025 (Salesforce Help).
- Processes: open Setup > Process Automation > Process Builder.
Leave validation rules out of the matrix. They block a save, but they do not write fields.
For a list you can export, run this query in the Developer Console with the Use Tooling API box checked. SOQL (Salesforce Object Query Language) is how you query Salesforce.
SELECT ApiName, ProcessType, TriggerType, RecordTriggerType, TriggerOrder
FROM FlowDefinitionView
WHERE TriggerObjectOrEventLabel = 'Opportunity' AND IsActive = true
Step 2: Build the field-write matrix
Make a sheet. Put each written field in a row and each automation in a column. Mark a cell when that automation writes that field.
- Flows: read every Assignment, Update Records and Create Records element.
- Apex triggers: search the code for lines such as
opp.StageName =. Note if the trigger is before or after. - Workflow rules: read the Field Updates section of each rule.
Any row with two or more marks is a suspect. Color those rows red.
Swipe sideways to see all columns
| Field | Flow: Opp_SetForecast | Trigger: QuoteSync | Workflow: Stage_Update |
|---|---|---|---|
Opportunity.ForecastCategoryName | Writes | Writes | |
Opportunity.NextStep | Writes | Writes | |
Opportunity.Amount | Writes |
In this example, two fields are suspects. Amount has one writer, so it is safe.
Step 3: Rank the suspects
Rank by harm, not by count.
- Save volume.
Opportunity.StageNamechanges on most edits. A rarely edited admin field matters less. - Who reads the field. Reports, routing, integrations and other flows all spread a wrong value.
- AI agents. An agent acts on the value it reads. If the value flips, so do its answers.
Fix the top three suspects first. Then plan the rest.
Step 4: Test the fix in a sandbox
- In a sandbox, edit a test Opportunity so every suspect automation fires.
- Read the debug log. Each flow and trigger shows in the log in the order it ran.
- Apply one fix from the next section.
- Repeat the same edit. Expected result: one writer, the same value every time.
If the value still changes, a writer is missing from your matrix. Check managed package triggers and after-save flows that update the same record.
How do I fix a race condition?
Swipe sideways to see all columns
| Pattern | When to use it | What to do |
|---|---|---|
| Merge flows | Two flows write the same field | Combine the logic into one flow with a Decision element. Retire the other. |
| One trigger per object | Two triggers on one object | Move the logic into one trigger that calls handler classes in a fixed order. |
| Retire workflow rules | A workflow field update is one of the writers | Rebuild it in Flow, test, then deactivate the rule. |
| Set Trigger Order | Several flows must stay separate | Give each flow a Trigger Order, spaced out, such as 10, 20, 30. |
| Pick one owner per field | Any shared field | Write down which automation owns the field. Others may read it, not write it. |
Here is a minimal one-trigger pattern:
trigger OpportunityTrigger on Opportunity (before insert, before update, after insert, after update) {
OpportunityTriggerHandler.run();
}
Watch for recursion too. Apex allows a trigger stack depth of 16 when triggers fire other triggers (Salesforce Limits: Apex Governor Limits). Past that, the save fails.
The undo is the same for every pattern. Keep the old flow version and the old trigger code until the next release passes. If the fix breaks something, reactivate the old version.
Which tools help detect race conditions?
Swipe sideways to see all columns
| Tool | What it shows | Limit |
|---|---|---|
| Flow Trigger Explorer | Record-triggered flows per object, in run order | Flows only, no triggers or workflow rules |
| Debug logs | The real run order for one save | One record at a time |
| Org Check (Salesforce Labs) | Metadata inventory, including flows and triggers | No field-write matrix |
| Clientell AI | Which flows, triggers and rules write each field | Needs a connection to your org |
Salesforce Optimizer is no longer an option. Salesforce has retired the Optimizer app (Salesforce Help).
How do I stop new race conditions?
- Make one trigger per object a team rule.
- Build no new workflow rules or processes. Use Flow.
- Prefer before-save flows for same-record field updates. They are faster and start no extra save.
- Ask for a field-write list with every new flow. The reviewer checks it against the matrix.
- Track new automation with change intelligence, so a new writer shows up before users see a wrong value.
For older flows, our flow cleanup guide covers names, fault paths and retiring old versions.
How can Clientell AI help?
Clientell AI reads your org in read-only mode. It lists every flow, trigger and rule that writes a field, and ranks the overlaps. Then it drafts the fix, such as a merged flow or a Trigger Order change. It tests the change in a sandbox and asks before it changes anything in production. Platform deployments can roll back. See our security and privacy page.
Try it in Clientell AI: "List every automation that writes Opportunity fields, and show fields with two or more writers."
Start the 14-day trial, no card. Clientell MCP is $249 a month and Clientell Platform is $500 a month. See pricing.
Common questions about Salesforce flow race conditions
How is a race condition different from a recursive trigger?
A recursive trigger updates a record, which fires the same trigger again. A race condition is two separate automations writing the same field. Both cause odd values, but the fixes differ.
Do before-save flows remove race conditions?
Not fully. A before trigger still runs after a before-save flow and can overwrite its value. Two before-save flows on one field also compete, unless you set Trigger Order.
Can validation rules cause race conditions?
No. Validation rules do not write fields. They can still block a save that another automation started, which looks similar.
Does Trigger Order work for Apex triggers?
No. Trigger Order applies to record-triggered flows. For Apex, use one trigger per object that calls handler classes in a fixed order.
Can I check for race conditions in a sandbox?
Yes. Every sandbox copies your production metadata, including flows and triggers. Run the matrix and the debug-log test there first.
Sources
Salesforce documentation
- Triggers and Order of Execution
- Triggers
- Order Record-Triggered Flows
- Meet Flow Trigger Explorer
- Apex Governor Limits
- End of Support for Workflow Rules and Process Builder
- Salesforce Optimizer App Retirement
Last reviewed October 2026
Last updated: October 22, 2026




