Salesforce Batch Apex Limits

The Salesforce Batch Apex limits have been a topic of heated discussion in many Salesforce  online forums. Many have argued that it is possible to submit more batch jobs than the required limit of five inactive or queued jobs while others have said it is impossible and that it complicates matters more. However, it is simply a question of whether one has clearly followed instructions or not. 

Salesforce Batch Apex Limits 

Submitting Batch Jobs Beyond The Limit

Thanks to the Apex Flex Queue pilot you can actually submit more than the allowed five active or queued batch jobs. Remember that any of the jobs in the holding status have already been submitted but haven’t been passed by the system. These jobs are therefore placed in this special separate queue known as Apex flex queue.

It is possible to have more than 100 batch jobs in the Salesforce Batch Apex flex queue but this can be rectified as soon as the system resources avail themselves. The system will automatically pick the jobs in holding state and transfer them to batch job queue. This action then immediately changes the state of the moved jobs from “holding” to “queued.” These queued jobs will then get executed as soon as the system is able to process any new batch jobs.

Unless the administrator intervenes, the jobs submitted will be processed by the order that they were submitted. It is possible to modify the jobs that have been placed in the flex queue and decide the order that the system will process them. For example, you can move a single batch job to first position in that holding queue and make it the first job to be processes when the system begins picking up the next job from the queue. 

Monitor & Reorder

It is also possible to monitor and reorder any batch jobs held at the flex queue from the user interface. Simply go to Setup and then click “Jobs/Apex Queue. You will see a page that has a listing of all the batch jobs whose status is “Holding” along with a bit of information on the job. 

Jobs are automatically numbered by the order of submission. You can simply click “Reorder” for a certain job to change its position. The system will immediately put the job in the specified position. However, there are exceptions such as when you specify a position that is bigger than the number of jobs found in the queue, the job will move down the queue while specifying a position lesser than one will simply move it to the start of the queue. The order remaining jobs will automatically be reordered and renumbered.

Avoiding The Salesforce Batch Apex Limit Error

Sometimes you will get the error message saying that you have attempted to schedule too many batch jobs. Sometimes you will even get a Developer script email when you hit the limit but not all the time. What you should do in order to resolve this is simply count the current jobs that the system is executing. You can find this information by checking the AsyncApexJOb table. Before using the database.executebatch option in a scheduled class, consider trying the method that Salesforce as suggested for releasing more than five batch jobs and not hitting the Salesforce Batch Apex limit. 

Amanda McDonnald
Amanda is the Lead Author & Editor of Rainforce Blog. Amanda established the Rainforce blog to create a source for news and discussion about some of the issues, challenges, news, and ideas relating to Salesforce usage.
Amanda McDonnald on sabtwitterAmanda McDonnald on sabgoogle