I am receiving the following error for some of my batches every here and there:

You've exceeded the limit of 100 jobs in the flex queue for org 00D6A000000vKLe. Wait for some of your batch jobs to finish before adding more.

Well, how can I have my code "Wait" until there is more space in the queue?

1 Answer 1


You probably need to check the number of jobs and then use an integer to make sure that there is a space for a new job. You can use this query to get exactly that:

Integer flexQueueSize = [
   FROM AsyncApexJob 
   WHERE Status = 'Holding' FOR UPDATE];

I think that this should help you to avoid reaching the flex queue limit.

A more sophisticated solution can be found here: https://www.jitendrazaa.com/blog/salesforce/framework-to-fix-governor-limit-of-100-jobs-in-flex-queue/

  • The framework approach is good if you control the majority of the code using the batch queues. Not so great if you don't. It is quite strange that the flex queue is as limited as it is, TBH. I guess it is because it allows for a very large JSON serialization footprint for the Batchable instance being executed/queued.
    – Phil W
    Oct 21, 2019 at 21:10
  • What does FOR UPDATE do? Why is it helpful in this scenario - Just trying understand the foundation of this query. Oct 23, 2019 at 12:27
  • FOR UPDATE basically locks the jobs and it will not allow any changes. The status Holding is related to Flex Queue jobs, up to 100.. help.salesforce.com/… Use the Integer to find out how many are already in Holding. Oct 23, 2019 at 20:16

You must log in to answer this question.

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