9

Do jobs placed in apex queue are actually executed the order they've been put in?

Or is this expected by developer to be implemented manually by using chaining?

10

No, I don't believe the order of execution for Queueable Apex is defined. They "will be processed when system resources become available" (Source). The AsyncApexJob records that represent the queued jobs don't have a concept of ordering (other than the created date).

Instead you should use chaining, which is defend in the docs as:

If you need to run a job after some other processing is done first by another job, you can chain queueable jobs.


The Apex Flex Queue for batch jobs is something different again. It does however have the concept of reordering.

|improve this answer|||||
  • 1
    The problem is, of course, we've all observed that older jobs go before newer jobs. We have no idea if this is intentional, or if it'll change. Future calls also seem to work the same way for now. It'd be interesting to see if we could get the Word on the matter. – sfdcfox Jun 23 '16 at 0:29
  • 1
    @sfdcfox My concern with relying on the observed ordering is that it could break. I could see the proposed pilot changes in Bigger Apex Limits with Enhanced Futures and Run Future Methods with Higher Limits shuffling when async jobs run. – Daniel Ballinger Jun 23 '16 at 0:48
  • Those pilot programs are ancient. Who knows if they'll ever see the light of day. I wasn't disagreeing with this answer, of course, just that we don't know what we don't know. One should definitely use chaining if the order is dependent. – sfdcfox Jun 23 '16 at 1:50
  • 1
    Had a look at data and seems around 10% of the transactions ran earlier than transaction created before it. – dzh Jun 23 '16 at 13:03
  • Apparently Platform events could be another mitigation for ensuring the sequence of events. – dzh May 15 '17 at 2:43

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.