35

Is there any way, either using apex or the API to unschedule a scheduled job?

3
  • Are you wanting to upgrade the scheduled class or similar? There's a nice application of Type.forName you can use for decoupling classes if this is the case... Jan 17, 2014 at 2:01
  • @user320, your comment intrigues me. Can you answer this question: salesforce.stackexchange.com/questions/24446/… ? Jan 17, 2014 at 5:12
  • @DanielHoechst Peter Knolle has got ya covered Jan 17, 2014 at 10:28

2 Answers 2

34

System.abortJob(Id) can do this. Simply pass in the Id of the CronTrigger for the job in question.

You'll note the docs specifically mention System.schedule results can be passed in, which would represent the scheduled job id; this same value can be obtained from the CronTrigger table.

1
  • I wasn't sure if abortJob() would take a schedule, thanks for clarifying.
    – greenstork
    Jan 17, 2014 at 16:16
20

You can try something like this :

List<CronTrigger> abort_job = [SELECT Id FROM CronTrigger limit 1];
    for (CronTrigger t : abort_job) { //for each record
     System.abortJob(t.Id); //abort the job
    }

http://www.interactiveties.com/blog/2012/batch-apex-test.php

1
  • 1
    Ha, beat you by 30 seconds! Good answer. Jan 17, 2014 at 0:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .