Cannot delete AsyncApexJob using System.abortJob

I’m facing the “ghost” job issue in an organization (thankfully is a sandbox). I had a class scheduled to run in a daily basis, and it was working fine, until I accidentally scheduled it again (2 jobs for the same class).

It ran, and scheduled itself again (the scheduling part is in the code, I didn’t use SF’s UI to set it up). After that I went to see the scheduled jobs, and excluded both of them.

After this whole story, I tried to edit something in the class, and Salesforce won’t allow me to because supposedly the class has jobs pending or queued. When visiting the Apex Jobs page, indeed, there is a job that is marked as ‘queued’. But I can’t seem to delete it. When I run System.abortJob('thejobIdhere') Salesforce throws me an error:

System.StringException: You can't abort scheduled apex jobs by calling
system.abortjob with an AsyncApexJob ID. You must call system.abortjob
with the parent CronTrigger ID.

But that CronTrigger Id doesn’t exist in the system anymore, so I can’t delete the job.

I have seen an issue like that at Salesforce Dev Community (https://developer.salesforce.com/forums/?id=906F0000000BOuqIAG), an answer to a similar question in here (How to delete AsyncApexJob with Queued status – doesn’t work for me), also there is a fixed issue (https://success.salesforce.com/issues_view?id=a1p30000000STwPAAW), but I am facing the issue.

What can I do to exclude this queued job, so I can edit my class?

Answer

EXCEPTION: System.StringException: You can’t abort scheduled apex jobs by calling system.abortjob with an AsyncApexJob ID.

You must call system.abortjob with the parent CronTrigger ID.

I tried same in workbench with lowed api version then it worked. I was able to delete 2 jobs in API version 32. Follow these steps to run this statement:

  1. login to “https://workbench.developerforce.com/login.php
  2. On right corner, it will be showing your name and API version. Click on that link
  3. There you will find change API version, change it to 32
  4. Go to Utilities >> Apex Execute
    There run this command with job Id

I believe this would help you. Please let me know if you have any other questions, I would love to help you in that as well.

Attribution
Source : Link , Question Author : Renato Oliveira , Answer Author : Adrian Larson

Leave a Comment