I have a few apex jobs which become stale (i.e. they just lie around in scheduled jobs queue with no nextfiretime) if an exception is hit while running the schedulable class. I cannot abort these jobs using the System.abort(jobId) since the job is not running. What is the best way to delete such stuck/erroneous apex jobs with no next fire time? Should I just query the cronTrigger objects and delete them?
List<CronTrigger> ctriggers = [SELECT Id, NextFireTime FROM CronTrigger
WHERE CronJobDetail.Name like 'JobName%'
And NextFireTime = NULL];
delete ctriggers;
abortJob
? This is information you can edit into your post to make it easier to answer.CronTrigger
orAsyncApexJob
doesn't support delete call