Salesforce: Problem Deleting Batchable Apex Class

Recently, I encountered a weird error when trying to delete a batchable Apex class from Salesforce instance. The error was:


This apex class is referenced elsewhere in Remove the usage and try again.




The reference was pointing to an Apex Job. Initially, this was a bit weird as I had checked that the Apex Job status was shown as Completed before deleting the Apex class. After doing some study, I found that this is related to one of the “error” Apex Job but with status Completed. To be specific, the Apex Job died at the execute() method due to stupid code that I have written and it never reaches the finish() method to close the Apex Job execution properly. The Apex Job is still considered open at the backend even though the status is Completed.


If you encounter the similar issue, you can perform the following:

  1. launch Developer Console
  2. open Execute Anonymous Windows
  3. paste the code: System.abortJob(”);
  4. click Execute to run the script

This should kill off the job and you can proceed to delete the Apex class now.