No. Salesforce makes no guarantee that batch chunks execute in the order returned by start. Chunks may run in parallel, complete out of order, and even retry — your execute method must not assume any sequencing.
What the docs explicitly say
From the Apex Developer Guide:
“Batches of records tend to execute in the order in which they’re received from the start method. However, the order in which batches of records execute depends on various factors. The order of execution isn’t guaranteed.”
Translation: never depend on order.
What can cause out-of-order execution
| Cause | Effect |
|---|---|
| Apex Flex Queue prioritization | Higher-priority jobs jump ahead |
| Platform parallel workers | Multiple chunks of the same job can run concurrently |
| Retries after chunk failure | The retry slot may run after newer chunks |
| Apex Job server distribution | Chunks dispatched to different processing nodes |
Why this matters in practice
Code that looks correct but breaks under out-of-order execution:
// BAD — assumes chunks run in order
public void execute(Database.BatchableContext ctx, List<Opportunity> scope) {
for (Opportunity o : scope) {
// We want to set Sequence_Number__c to a running counter
// starting from 1 in chunk 1
o.Sequence_Number__c = nextNumber++;
}
update scope;
}
If chunk 5 runs before chunk 3, the sequence numbers are wrong. Every assumption of “chunks run sequentially” breaks here.
What you can rely on
| Guarantee | Status |
|---|---|
start runs once | Yes |
execute runs once per chunk | Yes |
finish runs after all chunks complete | Yes |
All records returned by start get processed | Yes |
| Chunks run sequentially | No |
Chunk order matches start query’s ORDER BY | Often true, but not guaranteed |
| All chunks see the same database snapshot | No (each chunk re-queries) |
How to write order-independent code
- Don’t share state across chunks unless you use
Database.Statefuland don’t depend on the order of updates. - Compute relative values from the record itself, not from a running counter.
- Idempotent operations — running a chunk twice should produce the same result as running it once.
- External numbering — if you really need sequence numbers, generate them in a single sync step before batching.
The exception: Database.Stateful with care
Database.Stateful preserves member variables across chunks, but does not guarantee chunk order. So this still has the bug above:
public class StatefulCounter implements Database.Batchable<sObject>, Database.Stateful {
private Integer counter = 1; // survives, but assigned non-deterministically
// ...
}
State persists; sequence doesn’t.
Common interview follow-ups
- Does
ORDER BYinstartguarantee chunk order? — It guarantees the records within a chunk are ordered. Across chunks, you can’t depend on it. - Are chunks ever truly parallel? — Sometimes, yes — Salesforce can run multiple chunks of the same job concurrently in production.
- How do I unit-test for out-of-order behavior? — Hard. Most teams test the contract (every record gets processed) rather than the order.
Verified against: Apex Developer Guide — Using Batch Apex. Last reviewed 2026-05-17.