Could anyone explain more what 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. means? Seems like we can't be sure of returned records order or not?

  • What difference order by makes here, ultimately batch will process all the records. Jun 6 at 15:50

No, that isn't quite what that section from the documentation is saying.

If you ORDER BY your SOQL query in start(), the platform does not guarantee that the execution of batches will be in the same order as the records are in the query. Say for example you order by Order_Num__c, and your records have values from 1-10, and you are running with batch size 2. Your execute() method may be called with the batches


where some of the batches are apparently out of order relative to the key on which the query was ordered. Batches are run asynchronously and their order relative to one another is not guaranteed.

  • But we can be sure that inside all chunks we will get right order, correct?
    – pincet
    Jun 6 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.