There are two most common ways to revert your changes back to Salesforce sandbox from production:
1.) Force.com IDE
2.) Salesforce Migration tool (ANT)
Using Force.com IDE :
If you are already using force.com 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="http://soap.sforce.com/2006/04/metadata"> <apiVersion>33.0</apiVersion> <status>Active</status> </ApexTrigger> <?xml version="1.0" encoding="UTF-8"?> <ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>33.0</apiVersion> <status>Deleted</status> </ApexTrigger>
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 Force.com -> 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 Force.com IDE then you can go for this option as Force.com 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 Force.com 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 Force.com 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="http://soap.sforce.com/2006/04/metadata"> <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="http://soap.sforce.com/2006/04/metadata"> <types> <members>ClassToBeDeleted1</members> <members>ClassToBeDeleted2</members> <members>ClassToBeDeleted3</members> <members>ClassToBeDeleted4</members> <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.
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.