function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Batchable class stuck due to Completed Apex Jobs. Unable to delete.

I uploaded a class implementing the Database.batchable interface into our live environment. It ran with a couple of errors and I decided to remove it and go another route.


The problem is that I now seem to be unable to remove the class. I tried cleaning out the contents of the class, like thus:



global class CalcSummaryBatch {	



The class above saved successfully without any errors, but Salesforce still refuses to allow me to delete the class, or save it as Inactive.


Here's the error that I'm getting: "This apex class is referenced elsewhere in Remove the usage and try again.: Apex Job - xxxxxxxxxxxxxxxxxxx."


Here's the log under Setup > Monitoring > Apex Jobs. I double-checked, and all jobs are at a Completed status:

(There are about 20 such messages as the one below, all with status "Completed", and all the Apex Job Ids are listed as why the class cannot be deleted, in the error above)

 Submitted Date
Job Type
Status Detail
Total Batches
Batches Processed
Submitted By
Completion Date
Apex Class
Apex Method
 <nothing listed here>
 4/10/2011 11:00 PM Batch Apex
 First error: Attempt to de-reference a null object 0 0 1 xxx 4/10/2011 11:00 PM CalcSummaryBatch  <nothing listed here>
Afzal MohammadAfzal Mohammad

Have you removed it from "Scheduled Jobs" list as well? May be it is still there in the scheduled list.


And also there is no way to remove a class once it is deployed to production, unless you request salesforce's premium support to do so for you.


Hope that helps.




Hi Yo! Thank you for the suggestion, but there's nothing in the scheduled jobs list as well.


I usually remove the file in production via the eclipse IDE. Set up a new project using your production login credentials. Then when you delete a file from the file explorer on the project in production, it will prompt you for an option to "delete from server?" Click on yes to remove the file from the environment.

Thinking back to my last use of batched apex, I'm pretty sure the entries in completed apex jobs get deleted after 3 days, so you may just need to play the waiting game.

Bob, it looks like you're right! I checked the Apex Jobs status today, and the number of items whittled down to the last 7 days. I'll try deleting it again when the list clears. Thanks for your help!



You can always send in a support request to clear your apex job list. Wonder if it's faster to wait though lol.


Completed jobs do not maintain dependencies.  This job is either referenced by an active scheduled instance or another class.  If you can create a case and send me the case number, I will follow up.





Product Management Director, Platform


I did a site-wide search in Eclipse (on triggers, classes, pages, componenets, etc) and no other file is referencing it. Nothing in the scheduled jobs list either.


The number of items in the Apex Jobs list is down to 2, both dated 4/10/2011 and both in Completed status, so it doesn't look like a 3-day or 7-day limit to clear out the list, and those 2 items in the list are still preventing deletion of the class (both job Ids are listed in the error message when I attempt to delete the classes again today).


I went ahead and opened a case, but the issue might resolve itself by tomorrow.


Thanks again, everyone, for your responses and suggestions.


I have the same problem.

Batch class is stuck, there is no reference but deployment from eclipse fails saying "somewhere in salesforce".

Where is Somewhere, is it in Hawaii?


I faced this same problem, and my workaround is to abort all jobs using an anonymous apex code executed from eclipse. This is what I did:


List<asyncapexjob> jobs = [select id from asyncapexjob];

for (asyncapexjob job: jobs) {




I was able to remove the offending class right after this.

Nicolas KadisNicolas Kadis
If you need to delete Apex Jobs, you can use System.purgeOldAsyncJobs(Date dt) (" target="_blank).
Deletes asynchronous Apex job records for jobs that have finished execution before the specified date with a Completed, Aborted, or Failed status, and returns the number of records deleted.
Nikhil KhivansaraNikhil Khivansara
@Nicolas, Thank you for the post, this did help me and did not have to wait for auto-deletion of the Apex Completed Job records.