5

Is there a way to abort currently running batch job in Salesforce? I tried to run the query below and all it did was remove all jobs from Scheduled Jobs section without stopping the one that is currently running in the background. Please help. I would like to do it without contacting Salesforce support

    List<CronTrigger> jobsToAbort = [select Id from CronTrigger where CronJobDetail.JobType = '7'];
for (CronTrigger job : jobsToAbort) { System.abortJob(job.Id); }
14

Please run a SOQL query on AsyncApexJob with Status filter. CronTrigger is used to retrive Scheduled jobs wherein AsyncApexJob returns Apex Jobs (Running, Aborted, Pending, Completed etc.)

SOLUTION:

Use Below Code:-

for ( AsyncApexJob aJob : [ Select id ,Status, ApexClass.Name 
                              from AsyncApexJob where Status!='Aborted' 
                               and Status!='Completed' ] ){

      System.AbortJob(aJob.Id);

}
  • Very useful for killing a job running amok. Thx. – abhi Jun 28 '17 at 18:56
  • 1
    This worked great for me, I could kill some jobs by Apex class name. Thanks. – Dinesh Wickramasinghe May 16 '18 at 14:14
4

Went to SetUp --> Monitoring --> Apex Jobs. There was Abort option :)

  • The navigation may have changed since this answer was written, but the page still exists here: Setup -> Monitoring -> Jobs -> Scheduled Jobs – dana Jul 17 '17 at 19:25
  • New path is : Setup > Jobs > Apex Jobs or Setup > Jobs > Scheduled Jobs – Dinesh Wickramasinghe May 16 '18 at 13:59
0

Note that if you are in Lightning the Setup path has changed from the above:

Environments > Jobs > Apex Jobs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.