1

As a follow up to this question, here are some questions I've not been able to find an answer for:

  1. How many batch jobs can you dispatch before you exceed governor limits? 100 or 105?
  2. Do scheduled jobs and batch jobs sit in the flex queue together? Or do scheduled jobs have their own queue with their own governor limit?
  3. In the case of batch jobs, how exactly would I check whether I'm over the limit or not?

Thanks for the help.

0

Refer to this link for more info on batch apex: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

1. How many batch jobs can you dispatch before you exceed governor limits? 100 or 105?

In a single execution, the limit for Database.executeBatch() is 100 with Apex Flex Queue.

With the Apex flex queue, you can submit up to 100 batch jobs.

The outcome of Database.executeBatch is as follows.

  • The batch job is placed in the Apex flex queue, and its status is set to Holding.

  • If the Apex flex queue has the maximum number of 100 jobs, Database.executeBatch throws a LimitException and doesn’t add the job to the queue.

2. Do scheduled jobs and batch jobs sit in the flex queue together? Or do scheduled jobs have their own queue with their own governor limit?

They have separate limits, except for when you schedule a batch job using System.scheduleBatch().

All scheduled Apex limits apply for batch jobs scheduled using System.scheduleBatch. After the batch job is queued (with a status of Holding or Queued), all batch job limits apply and the job no longer counts toward scheduled Apex limits.

3. In the case of batch jobs, how exactly would I check whether I'm over the limit or not?

When system resources become available, the system picks up the next job from the top of the Apex flex queue and moves it to the batch job queue. The system can process up to five queued or active jobs simultaneously for each organization. The status of these moved jobs changes from Holding to Queued. Queued jobs get executed when the system is ready to process new jobs. You can monitor queued jobs on the Apex Jobs page.

You can check the current active jobs in apex:

Integer batchJobsActive = [SELECT COUNT() FROM AsyncApexJob WHERE JobType = 'BatchApex' AND Status IN ('Queued', 'Preparing', 'Processing')];

You can check the Flex Queue jobs in apex like this:

Integer batchJobsHolding = [SELECT COUNT() FROM AsyncApexJob WHERE JobType = 'BatchApex' AND Status = 'Holding'];
| improve this answer | |
  • Is the flex queue's limit 100 for just holding jobs? – coldspeed Feb 9 '17 at 5:41
  • Yes, see here: developer.salesforce.com/releases/release/Spring15/FlexQueue "The Apex flex queue enables you to submit up to 100 batch jobs for execution. Any jobs that are submitted for execution are in holding status and are placed in the Apex flex queue. Up to 100 batch jobs can be in the holding status." – Bob Lopez Feb 9 '17 at 5:49
  • Once again, hanks a lot! – coldspeed Feb 9 '17 at 5:50

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.