Loading

Abort a Long-Running Asynchronous Apex Job in Salesforce Platform

Дата публикации: Apr 2, 2026
Описание

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. 

 

Example Scenario

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.

Решение

Abort Asynchronous Apex Jobs in an Anonymous Apex Block

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);
   }      
 }

Abort Asynchronous Apex Jobs from the Salesforce User Interface

  1. From Setup, in the Quick Find box, enter Scheduled Jobs, and then select Scheduled Jobs.
  2. Click Del next to the job that you want to delete.
  3. Click Ok.
Номер статьи базы знаний

000385103

 
Загрузка
Salesforce Help | Article