12

We have a discussion going on, to know now exactly what the limits are on batch apex jobs. The docs are really not clear on this. In this document it states that "Up to five queued or active batch jobs are allowed for Apex".

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm#BatchApexLimitsSection

But then in the governor limits doc it states that you can have up to 5 concurrently running batches and up to 100 Up to five queued or active batch jobs are allowed for Apex. batch jobs.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

But now if you schedule an apex batch job through the interface and you schedule it to run every day for example then the status is queued.

So what is now the correct limit? do batch jobs that are in status queued counting to the 5 limit or to the 100 limit?

Thank you

Sven

1 Answer 1

8

In practice, Queued counts toward the limit of 5. We have added code to protect against the dreaded 'Attempted to schedule too many concurrent batch jobs in this org' LimitException (since you can't catch LimitExceptions)

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

if(enqueuedJobs >= 5){
    throw new TooManyBatchApexJobsException();
}

This article is confusing and contradictory too:

http://help.salesforce.com/apex/HTViewSolution?id=000182449&language=en_US

Relevant contradictory statements from that article:

  • Batch Apex can have 5 concurrent (simultaneous) jobs running in parallel.
  • That is, explicitly, the number of Batch Apex jobs whose status in the AsyncApexJob table are 'Processing' or 'Preparing'.
  • A job is not executing when in Queued or any other status.
  • Scheduling more than 5 Batch Apex jobs returns the error "Attempted to schedule too many concurrent batch jobs in this org"
  • You may sometimes receive a Developer script exception e-mail when this limit is reached, but not always. (This is also by design).

You must log in to answer this question.

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