0

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?

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

1 Answer 1

3

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

1,2
5,6
3,4
9,10
7,8

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .