+ Start a Discussion
Admin User 9994Admin User 9994 

Delete Apex Class from production without test class

We have deprecated Apex code that needs to be removed from Production. When attempting to do so either through Workbench, or through Visual Studio Code, the usual code coverage error prohibits me from doing so because there is not enough coverage. This is a catch 22, because the Classes/Triggers I need to remove are the cause of the lack of code coverage. The functionality they cover is being removed, so there's nothing to write a test Class for.
AbhishekAbhishek (Salesforce Developers) 
I am 99.999% sure that you cannot delete the class through the Salesforce Web interface. You cannot do it through Changesets (https://help.salesforce.com/articleView?id=changesets_best_practices.htm&type=5).

I believe that you have to use something backed by the metadata API such as the Force.com IDE or the Ant Migration tool with a destructiveChanges (https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_deleting_files.htm?search_text=destructive)file. That is no help for you, however, since you'd need the token in your situation.


Below are the steps:

1) From Force.com IDE, select the class that you want to delete (Look for .xml extension )

2) Open that .xml version of your class and change the Status tag to Deleted.

3) Right-click and save the file.

4) Now select the "SRC" folder and right-click--->Select  Force.com---> select Deploy to server

5) Log into your production org and follow the steps.


Note: if you have any test class for the class that you are deleting make sure you do the same as above and then select those 2 classes for final deployment.

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Admin User 9994Admin User 9994
Thanks Abhishek,

I used to use Force.com IDE with Eclipse but have been informed that it's been replaced with Salesforce DX in Visual Studio Code. I've setup my environment there and do pretty much the same command, but it still executes code coverage check even just trying to change the metadata state. I also tried using the Workbench to use destructive changes xml, but same result there as well.