Thursday 10 December 2015

System.abortjob() in salesforce

    Batch and Schedule apex jobs aborting using system.abortJob
abortJob(jobId)
Stops the specified job. The stopped job is still visible in the job queue in the Salesforce user interface.
Signature
System.abortJob(String jobId)
Parameters
jobId
Type: String
The jobId is the ID associated with either AsyncApexJob or CronTrigger.

Ø  We need to execute following code in developer console to abort single job.
         EX :   System.abortJob (003j000000QQHjr”);

Ø  We need to execute following code in console to stop multiple jobs.

Id ids = [SELECT id, name FROM ApexClass WHERE Name = 'AccountUpdate'].id;

List<AsyncApexJob> jobs = [SELECT Id, ApexClassId, Status FROM AsyncApexJob WHERE ApexClassId =: ids AND Status IN ('holding','Queued','Preparing')];
System. Debug ('jobsjobsjobsjobsjobs ‘+jobs);
For (AsyncApexJob job: jobs) {
    System.abortJob (job. ID);

}


    =============================================================

Complete Salesforce CPQ training Free videos

Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...