Is there any way, either using apex or the API to unschedule a scheduled job?
-
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... – bigassforce Jan 17 '14 at 2:01
-
@user320, your comment intrigues me. Can you answer this question: salesforce.stackexchange.com/questions/24446/… ? – Daniel Hoechst Jan 17 '14 at 5:12
-
@DanielHoechst Peter Knolle has got ya covered – bigassforce Jan 17 '14 at 10:28
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.
-
I wasn't sure if abortJob() would take a schedule, thanks for clarifying. – greenstork Jan 17 '14 at 16:16
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