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

1 comment:

  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