Thursday, January 9, 2020

How to abort the Scheduled batch job using Apex in Salesforce

The Scheduled batch job information internally stored in CornTrigger object in salesforce.

Ex:  let as assume you scheduled the batch job using System.schedule(jobName, cronExp, schedulable) method it returns the CornTrigger record Id.

String strCornExp = '0 38 * * * ?';
Id cornId = System.schedule('Test Job', strCornExp, new ScheduleJob());

Query the information based on record Id and use the System.abortJob(cornTriggerId); method to abort the scheduled job.

CronTrigger obj = [SELECT Id, CronJobDetail.Name, CronJobDetail.Id,State FROM CronTrigger where CronJobDetail.Name = 'Test Job'];
System.abortJob(obj.Id);

2 comments:

  1. I would like to thank you for the efforts you have made in writing this article. as we provide Sales Recruitment Agencies at affordable prices. for more info visit our website.

    ReplyDelete
  2. I read your post and this blog is very good. You have good knowledge on this. This post really impressed me. Thank you for sharing your knowledge with all of us.
    Singapore Online Job Vacancy 2021

    ReplyDelete