To abort long-running batch, future, or scheduled Apex jobs, use System.abortJob(). For batch and future Apex jobs, pass the AsyncApexJob ID associated with the job to this method. For scheduled Apex jobs, pass the CronTrigger ID associated with the job to this method.
A Salesforce administrator notices that a nightly Batch Apex job — designed to update Account records — has been running for over 12 hours without completing. Other scheduled jobs that depend on the same data are now queued and waiting. The administrator needs to locate and abort the stuck batch job to free up processing resources and allow the dependent jobs to run. This article walks through exactly how to do that.
Run this code. Replace 'YourAsyncApexClassName' with the name of the asynchronous Apex class. The SOQL query limits the list to 200 jobs. If you plan to abort more than 200 jobs, rerun the query.
List<AsyncApexJob> jobsToAbort = [SELECT Id, CronTriggerId, JobType from AsyncApexJob
WHERE ApexClass.Name = 'YourAsyncApexClassName' AND Status = 'Queued' LIMIT 200];
for (AsyncApexJob jobToAbort : jobsToAbort) {
if (jobToAbort.JobType == 'ScheduledApex') {
System.abortJob(jobToAbort.CronTriggerId);
} else {
System.abortJob(jobToAbort.Id);
}
}
Scheduled Jobs, and then select Scheduled Jobs.000385103

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.