function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
David Hien 8David Hien 8 

how to delete the above Schedule Jobs with for loop

How to delete the Schedule Jobs with for loop.
Best Answer chosen by David Hien 8
Ajay K DubediAjay K Dubedi
Hi David,

Please use this I hope you understand. 
(1)
 List<CronTrigger> abort_job = [SELECT Id FROM CronTrigger ];
    for (CronTrigger ct : abort_job) {
     System.abortJob(ct.Id); 
    }

(2) 
you can also use this.

for(integer i=0;i<=55;i=i+5){
 String CRON_EXP = '0'+i+'   * ?' ;
 CountbatchSchedule bt2= new CountbatchSchedule();
 Id jobId=System.schedule('updateAccountCount'+i,CRON_EXP,bt2);
 System.abortJob(jobId); 

 
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi

All Answers

Raj VakatiRaj Vakati
for(CronTrigger delCron: [SELECT Id FROM CronTrigger ])  {
    System.abortJob(delCron.Id);
}

 
Ajay K DubediAjay K Dubedi
Hi David,

Please use this I hope you understand. 
(1)
 List<CronTrigger> abort_job = [SELECT Id FROM CronTrigger ];
    for (CronTrigger ct : abort_job) {
     System.abortJob(ct.Id); 
    }

(2) 
you can also use this.

for(integer i=0;i<=55;i=i+5){
 String CRON_EXP = '0'+i+'   * ?' ;
 CountbatchSchedule bt2= new CountbatchSchedule();
 Id jobId=System.schedule('updateAccountCount'+i,CRON_EXP,bt2);
 System.abortJob(jobId); 

 
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi
This was selected as the best answer
David Hien 8David Hien 8
Thanks a lot Guys.