How to find number of pending batch jobs in Salesforce?

How to find number of pending batch jobs in Salesforce?

Sample Code:

List<String> batchStatuses = new List<String> {‘Holding’, ‘Queued’, ‘Preparing’, ‘Processing’};
List<AsyncApexJob> listPendingJobs = [SELECT Id FROM AsyncApexJob WHERE Status IN: batchStatuses];

listPendingJobs.size() gives the number of pending batch jobs in Salesforce

Cheers!!!

Leave a Reply