6

Under what circumstances does an org have a concurrent batch job limit of 2 rather than 5, and is there a way to determine this in apex?

We have code that assumes that 5 batch jobs can be scheduled concurrently, but today we got an error of Attempted to schedule too many concurrent batch jobs in this org (limit is 2) in an org.

  • are you sure this is not some kinda of a custom exception, as per the docs ASAIK the limit is 5 for any edition and any org – Rao Jan 8 '15 at 18:36
  • @rao, it's a System.LimitException being thrown. – xn. Jan 8 '15 at 18:45
  • Is this a production db or a sandbox? – Jagular Jan 8 '15 at 19:14
  • It's a Spring '15 Pre-Release org. – xn. Jan 8 '15 at 19:48
  • 1
    Got this response from Salesforce, "The limit for maximum number of batch jobs en queued for free orgs is 2 by default". Maybe that is true, asked for documentation. This wasn't the case before Spring 15. – TehNrd Jan 21 '15 at 18:58
4

This is a response I got from salesforce:

I just had a chat with one of our R&D experts and he mentioned that they are planning to remove this limit from next week's patch temporarily. When it comes back again there will be official documentation on the changes. He also mentioned that these were in the documentation initially, but were removed when the changes were removed. The removal was not fully applied, though, but will be applied with next week's patch release.

It would appear they changed the limit to 2 but provided no way to tell what the limit is in Apex and are rolling the change back. Eventually the limit will be set to 2 again and hopefully there will be someway to identify this limit in Apex as there is not today.

2

Salesforce Platform supports only 5 batch Jobs at any given point of time. However Spring '15 Release brings new feature called 'APEX FLEX QUEUE' to Salesforce platform where we can queue up to 100 Batch Jobs.

If you want to get enabled in your organization, you should install the critical update named " Apex Flex Queue critical update" via setup.

If you decide to use this feature, any jobs submitted are in Holding Status. You can monitor submitted Jobs through Jobs --> Apex Flex Queue

Detailed Documentation here

If you are not enabling this update, then use the following SOQL to determine the total number of Batch Jobs running. Based on the below SOQL, you can choose to execute Batch or not.

[SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]

More Information here in this Knowledge Article Number: 000182449

  • We are querying AsyncApexJob to check whether we've already hit the limit of 5, but we have 5 hard-coded because I didn't know it was possible for the limit to be 2. – xn. Jan 8 '15 at 19:51
  • Never sees this error before. Out of curiosity , do you guys schedule more than 2 jobs in single execution context? Not sure it would be a problem, just thinking out loud. – Jag Jan 8 '15 at 23:36
  • So just to clarify - in Spring 15 orgs, if we enable the Apex Flex Queue critical update, database.executebatch will put everything in the queue and process per the new functionality? And I can then remove any checks for 5 concurrent batches, and just check for the 100 queue exception? Trying to work out what I'll need to do to make this work effectively in Spring 15 orgs... – BritishBoyinDC Jan 22 '15 at 18:29

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.