39

Recently I've been running into issues where deployments were blocked due to a Schedulable job pending or in progress when I'd already cleared the Schedulable job from that class.

Any tips for resolving this issue? I've had success in the past by querying all CronTrigger objects and aborting the jobs that don't have a status of 'Deleted', but that has the unwanted side effect of cancelling all Dashboard Refreshes as well. I'm sure there is just a stuck job in there somewhere, but was curious if any of you code heads out there had other ideas ...

2 Answers 2

24

Has it something to do with this 'Known Issue'? http://success.salesforce.com/issues_view?id=a1p30000000STwPAAW

Update

While this is marked as fixed this issue still continues to come up from time to time. Fortunately Salesforce support can run a quick fix to address. Contact them and ask to run "fix for locked scheduled class" and include the deployment error message.

3
  • that would be it, thanks jason, how i love known issues Commented Sep 24, 2012 at 7:07
  • Worth noting...I was able to edit the code following the workaround; however, I am not able to actually delete the class...still get the phantom Scheduled Jobs. Commented Sep 24, 2012 at 19:43
  • Fyi, even though this issue has marked as resolved for some of my orgs I'm still getting this error message for ANT/Eclipse based deployments. Change sets work as expected. Commented Sep 30, 2012 at 19:16
11

Just to add to this, as I recently had the same issue.

You can log a case with support and they will look to remove ghost jobs.. however. This article provides some explanation and code that can be run in developer console. I suggest trying this first (if you are happy to delete all jobs) as it is quicker than going through support. This article solved my problem where i had the error:

This schedulable class has jobs pending or in progress

  • Make sure to read the article first.
  • Running this code will delete ALL scheduled jobs in the organization
  • You will need to reschedule all jobs manually after running this
  • If you are unsure of the impact of this, please contact your internal development team
  • If you wish to use ScheduleJob ID instead of cronTrigger ID to abort the job using System.AbortJob() use API version 32.0 or below

Code to execute:

List<CronTrigger> listCronTrigger = [select Id, CronExpression, EndTime, NextFireTime, OwnerId,
        PreviousFireTime, StartTime, State, TimesTriggered, TimeZoneSidKey from CronTrigger 
        where State = 'Waiting' or State='Running'];

System.debug('No of jobs: '+listCronTrigger.size());

If (listCronTrigger.size() > 0)
{
    for (Integer i = 0; i < listCronTrigger.size(); i++)
    { 
        System.abortJob(listCronTrigger[i].Id);
        System.debug('Job details ::'+String.valueOf(listCronTrigger[i]));
    }
}
3
  • 1
    Hey, can you post the relevant content from the article? Links tend to break over time.
    – Matt Lacey
    Commented May 6, 2016 at 1:47
  • 2
    Added the detail, from article for reference.
    – dacology
    Commented May 16, 2016 at 9:52
  • NB - the line If you wish to use ScheduleJob ID instead of cronTrigger ID to abort the job using System.AbortJob() use API version 32.0 or below means you query AsyncApexJob rather than CronTrigger
    – cropredy
    Commented Jun 27, 2019 at 22:00

You must log in to answer this question.

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