Salesforce | Roll back changes or delete unused classes/triggers from Production

| By Webner

There are two most common ways to revert your changes back to Salesforce sandbox from production:

1.) IDE
2.) Salesforce Migration tool (ANT)

Using IDE :

If you are already using IDE then you can go for this option to delete components from production.

Below are the steps:

1. Connect to the Sandbox Org using the IDE and find the class.

2. Open the matching .xml file of the class that you want to delete.

3. Change the Status XML tag from Active to Deleted.

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

<ApexTrigger xmlns="">




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

<ApexTrigger xmlns="">




4. To disable the trigger change it to Inactive and save the file.

5. Select the files (Code and XML) and then right-click on any of them.

6. Select -> Deploy to server.

7. Log into your production org and follow the same steps.

Salesforce Migration tool (ANT) :

If you are not already using The IDE then you can go for this option as IDE is quite a ‘heavy’ tool. Also there are number of dependencies issue you may face (a compatible version of Java, different IDE version etc).
The Migration Tool is a Java/Ant-based command-line utility for moving metadata between a local directory and a Salesforce organization. You can use the Migration Tool to retrieve components, create scripted deployment, and deleted deployment changes. Ant is easy to install and Use.
To deploy the destructive changes, we need a delete manifest file destructiveChanges.xml We also must have a package.xml file that lists no components to deploy includes the API version. Both files should be in the same directory as destructiveChanges.xml:

1. Open any text editor and add copy below code in the file. Save as the file with name ‘package.xml’

<?xml version="1.0" encoding="UTF-8"?> <Package xmlns=""> <version>33.0</version> </Package>

2. Then create a new file in Notepad and copy the below code into it :

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





<name>ApexClass</name> </types> <version>33.0</version> </Package>

3.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.

4. Now go to terminal in the file directory where these files are located and run the following command.

C:\>ant undeployCode

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.

Leave a Reply

Your email address will not be published. Required fields are marked *