Every now and then, I find I get a few jobs that are stuck in the queue which end up causing things like reports to stop being generated or stop pardot from syncing or just causing general chaos.
Note: this no longer works in Salesforce Orgs that have been upgraded past version 38, and apex must have an API version less than 39.
I usually run a very slight variation of the following code through the developer console if there are more than a dozen jobs still in holding. You can go to the developer console by clicking on your picture in the top right corner of Salesforce and then selecting “Developer Console”.
Then choose the Debug menu, and choose “Open Execute Anonymous Window”
for ( AsyncApexJob aJob : [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors FROM AsyncApexJob Where Status = 'Holding']) { system.abortJob(aJob.Id); }
Note: you should never run this exact apex from the developer console without running the query to see what would be ended. It’s completely possible that you will kill asynchronous apex jobs that need to run.
A very good variation through would only stop jobs that have been queued and waiting for quite some time would be to add the CreatedDate or LastModifiedDate to the query. Like this:
for ( AsyncApexJob aJob : [SELECT Id, Status, JobItemsProcessed, TotalJobItems, NumberOfErrors FROM AsyncApexJob Where Status = 'Holding' AND CreatedDate <= YESTERDAY]) { system.abortJob(aJob.Id); }
Eric Kintzer
Brian Cline