Back to insights

Automation Architecture, Save Order & Transaction Design

Salesforce order of execution is not an orchestration strategy

JSBC Labs8 min read

A sequence is not a design

A team fixes an Opportunity calculation by moving one Flow earlier, renumbering another and adding a guard to an Apex trigger. The test record now saves correctly. A month later, a managed package update adds automation, a roll-up changes the parent Account and the calculation runs again with a different intermediate value. Every component followed Salesforce's documented order of execution; the business outcome was still unstable because nobody owned the complete transaction.

The JSBC Labs position is that Salesforce order of execution is a platform sequence—not an orchestration strategy. It explains when validation, before-save flows, Apex triggers, workflow actions, after-save flows and other steps can run. It does not define the business capability, the authoritative component, the dependency contract or the acceptable side effects. Treat the sequence as a constraint around architecture, not the architecture itself.

Model the save as an automation graph

Salesforce documents a multi-stage server process for insert, update and upsert operations. One record change can also update related records, execute roll-ups, invoke package automation and re-enter parts of the save sequence. A flat list of Flows and triggers on the original object therefore hides the real shape of the work.

Build an automation map for each high-change object. Start with entry channels, then show before-save logic, Apex triggers, after-save work, cross-object updates, asynchronous paths and external effects. Mark which nodes can perform DML and which objects they touch. Add managed-package and standard automation even when the team cannot edit it. This graph exposes cycles, duplicate calculations and shared governor-limit consumption that a diagram of the published order alone cannot reveal.

Choose the transaction phase from the outcome

Salesforce recommends before-save record-triggered flows for updating or validating the triggering record. They run before Apex before triggers and avoid an extra database save. After-save flows have the record ID and can create or update related records, send email and call other capabilities, but updating the triggering record from that phase introduces another save and another opportunity for automation to run.

Place each rule in the earliest phase that can satisfy its contract, not the phase a builder happens to know best. Normalisation and same-record defaults usually belong before save. Related-record changes need an after-save or deliberately separated process. Work that does not determine whether the user's save succeeds should be evaluated for an asynchronous boundary. Record the reason in the design so later teams do not move logic between phases as a local performance fix.

Ordering controls are local, not universal

For before-save or after-save flows on the same object, Salesforce supports trigger-order values from 1 to 2,000. Values establish order only among flows of the same trigger type and still respect the wider order of execution. Flow Trigger Explorer can show and reorder those flows, but it cannot make an after-save flow run before a before-save flow or an Apex trigger.

Use order values to make a deliberate dependency visible within one lane. Leave gaps such as 100, 200 and 300 so new logic can be inserted without renumbering everything. Do not use numbering to create long hidden chains where Flow B assumes every internal detail of Flow A. Pass dependency through persisted fields or an explicit shared service, and document the prerequisite. If the sequence becomes the only expression of business logic, maintenance will eventually break it.

Create one accountable entry point per object

Salesforce Architects recommends one automation entry mechanism per object where practical and warns that the platform does not guarantee the execution order of multiple Apex triggers for the same event. For lower automation density, ordered record-triggered flows can provide a clear entry point. Higher-density objects may need a single Apex trigger with an intentional handler or metadata-driven framework.

This is not an argument for one enormous mega-flow or one monolithic handler. Partition logic into cohesive actions with precise entry conditions and one owner, then coordinate those actions through a visible layer. Mixing independent Apex triggers and numerous Flows on the same object should be a conscious exception with tested contracts. The objective is not tool purity; it is making responsibility, ordering and resource use understandable before production incidents force the discovery.

Control re-entry with state, not static flags

Salesforce notes that triggers can fire more than once in a transaction and that recursive saves skip parts of the normal sequence. Cross-object updates can also return to the original record through an indirect path. A transaction-wide static Boolean may stop an infinite loop, but it can also suppress legitimate processing for later records or later phases in the same bulk transaction.

Make automation idempotent and condition it on meaningful state transitions. Compare old and new values, track which record identifiers and actions have already been processed where necessary, and avoid DML when the intended value is already present. Test bulk updates containing mixed states, because a guard that works for one record can fail across two hundred. Re-entry protection should preserve valid work while preventing repeated side effects—not merely make the recursion error disappear.

Draw transaction boundaries around failure

Immediate record-triggered automation shares the save transaction. Salesforce's default error behaviour can roll back the triggering change when a record-triggered flow fails. The same atomicity is valuable for rules that must succeed or fail together, but it is a poor fit for slow enrichment, notifications or integrations whose availability should not control a user's database commit.

Classify each side effect by atomicity, latency and recovery. Keep essential consistency checks inside the transaction. Move independently recoverable work to an asynchronous path, queueable process or event-based pattern with idempotency, monitoring and reconciliation. An asynchronous boundary is not free reliability: it changes the error contract from rollback to eventual completion. Name the owner, retry policy and evidence required to prove that the deferred outcome happened.

Test the transaction, not isolated components

A Flow debug run or Apex unit test can prove one component's branches while missing the interaction that makes the production transaction unsafe. Build scenario tests from real entry channels and assert the final business state across all affected records. Include bulk loads, unchanged-field updates, cross-object roll-ups, validation failures, package-enabled environments and repeated saves. Measure queries, DML, CPU and asynchronous work at the full transaction level.

Govern the automation map as a production artefact. Review it when a Flow is activated, an Apex trigger changes, a managed package is upgraded or a new integration writes to the object. Monitor save failures, CPU growth, recursion symptoms and duplicate side effects. Order of execution should help engineers reason about platform behaviour. Architecture must ensure that every path through that order produces one owned, explainable and recoverable business outcome.

Official references

Continue reading