An Easier Way to Delete Apex Classes From Production

An Easier Way to Delete Apex Classes From Production

The purpose of this article is to:

– Highlight the problems faced when deleting Apex classes and triggers in a Salesforce production environment

– Describe in detail a lightweight and flexible solution that enables one to delete Apex classes and triggers from a Salesforce production environment quickly and easily

This article expands on the question and answers posted here.

The problem

The most common approach to deleting Apex classes and triggers in a Salesforce production environment is to leverage either the IDE or the Migration tool. These tools have a number of downsides, namely:

-The IDE is very ‘heavyweight’ and is known for being quite buggy sometimes and unpleasant to use.

-They have a number of dependencies (a compatible version of Java, different IDE version etc)

-Connectivity to Salesforce via the IDE may be an issue

-The migration tool (ANT) can take some time to learn how to use properly.

Apex classes and triggers cannot be deleted from a Salesforce production declaratively, unlike in sandbox orgs. This is because security for Apex in Salesforce production orgs is greatly increased. So how can one delete Apex classes and triggers from a production org without having to go through the inconvenience and time consuming effort of installing, testing and learning how to properly use these tools?

The answer can be to use Notepad* text editor and the super lightweight and easy to use Workbench suite. Using these tools, deleting Apex classes and triggers from Salesforce production is a breeze. Because Workbench is web based and text editors are already pre-installed and super easy to use, there’s no time spent on downloading, installing or testing the IDE or Migration tool (ANT).

What to do

Let’s say that you have a Salesforce production org that has two Apex classes that need to be deleted.

1. To achieve this via Workbench, create a folder on your desktop. I will call my folder ‘deleteClasses’.

2. Then go to Notepad (or another text editor) and copy and paste the below and save as the file with ‘package.xml’ and ‘All files (*.*)’.

<?xml version="1.0" encoding="UTF-8"?>

<Package xmlns="">




3. Then create a new file in Notepad (or another text editor) and copy the below into it:

<?xml version="1.0" encoding="utf-8"?>

<Package xmlns="">







Replace SomeClass with the name of your class that you wish to delete. If you have two classes that need to be deleted at the same time, you can simply add another <members> row into the file with the name of the other class, for example:

<?xml version="1.0" encoding="utf-8"?>

<Package xmlns="">








4. Save this file name as destructiveChanges.xml (note the capital ‘C’ in ‘changes’). Make sure the file is saved as ‘All files (*.*)’. More information on destructive changes can be found here.


5. Now there are two files in your folder. Open the folder, select both the XML files, right-click and select ‘Send To > Compressed Folder’. Keeping the default name of ‘package’ for the folder is fine.


6. You are now setup to deploy the destructiveChanges.xml file to Salesforce. To do this, go to Workbench and login with your credentials. It is recommended that you login to a Sandbox instance before you deploy the file to production.

7.  Select Migration > Deploy.

8. Click ‘Browse’ and select the .zip package file. Then check ‘Rollback on Error’, ‘Single Package’, and select Test Level with ‘RunLocalTests’. More information on the Test Level can be found here.


9. Finally, select ‘Next’ and then you will notice that the success or error results will be displayed in Workbench once the deployment process has been completed.

This is a very easy way to delete Apex classes and can be very handy if you need a lightweight tool to do the job.

Subscribe To The Monthly Newsletter

No Spam. No Rubbish. Just great content from the Salesforce Industry.

You have Successfully Subscribed!

25 thoughts on “An Easier Way to Delete Apex Classes From Production

  1. Here is another way to do it using IDE like IDE or MavensMate:

    1. IDE should be installed.
    2. Connect to the Sandbox Instance using the IDE and find the class or trigger that you want to delete.
    3. Open the matching .xml file, and change the Status XML tag from Active to Deleted.
    4. Or to disable the trigger change it to Inactive.
    Note: Apex class Status can only be changed to “Active” or “Deleted,” not “Inactive”.
    5. Save the file.
    6. Select the two files (Code and XML) using “Ctrl-click,” and then right-click on one of them.
    7. Select | Deploy to server.
    8. Provide your credentials for the Production org and follow the steps.


    1. Hi Joey.. I have tried above steps for UAT sandbox, after changing to Active state to “deleted” sate in meta data I can save the file, then next step I don’t option to Deploy to server/save to server.
      Please help me here.


  2. I have come across very simplified tool Metaforce, it can be installed as plugin in chrome.
    User interface is very simplified for deleting metadata.

  3. Hi Joey.. I came across your points, at 7th point I’m getting only “ > show in salesforce web ” this option. Pls help me out, its urgent.

    Vinod Kumar

    1. When deleting triggers the destructiveChanges.xml file needs to contain

  4. Thank you for this helpful tutorial. I’m trying to delete a trigger. I’ve uploaded the zip file but the deployment failed because of some failed tests. Any clue how to bypass that and delete the trigger anyway?

  5. Hi Sir, I have tried to delete the classes from my Sandbox by following the steps as mentioned above (by using Workbench tool). Now how can I delete the same classes from my Production org ?
    Please assist me.

  6. Thank you so much for this! I needed to delete two apex classes and was struggling mightily with the Force. come IDE but this worked like a dream.

  7. Man!!!! You are a true genius. I just found this after spending enormous unsuccessful hours in IDE. This is a life saver. I successfully deleted classes from Production without any issue.

    Thank you so much!!!!!

  8. I wish to convey my respect for your kind-heartedness for folks that have the need for guidance on the question. Your special commitment to getting the message all-around ended up being unbelievably valuable and have in most cases made workers like me to reach their dreams. This warm and helpful guideline indicates so much to me and extremely more to my mates. Best wishes; from each one of us.

  9. Love this article. Quick question, when deleting apex classes and triggers in production do you have to run the tests at all? Can you choose to not run any tests?

    1. Kim, tests have to be run in Production, but if you have test classes directed directly at the apex class to be deleted, you can specify to only run that test class.

  10. Thanks David,

    So I have a scenario where we have to delete apex classes, triggers, and test classes. They all depend on each other. When I opt to run local tests it fails but when I choose not to run tests at all it’s successful. Can I choose not to run local tests when deploying to prod ?

  11. Pure gold! Have been trying to delete old/unused classes and triggers without luck. This guide worked perfectly. Definitely recommend running in a test environment to ensure all goes well; and then altering issues as they arise. Thanks!

  12. I have used these steps before with no problem, but when trying to use this today, I am getting a “Bad file:Content is not allowed in prolog.” error when it is trying to perform the delete through workbench.

    Anyone know how to correct? The only difference in my files from what is specified in the blog is the Class Name.

    1. So, to close a loop here. It appears that this no longer works on Mac (not sure why) but using the same files and everything it worked just fine on a PC.

      At least I have a workaround!

  13. Hi, I’ve created my for a trigger and a class that I would like deleted. When I run it in the Workbench, I’m not getting any errors, but the trigger or the class are not being deleted.
    In the tree that appears below the results section on Workbench, Success = true, but Deleted = false
    Can anyone offer any suggestions?

Add Comment