Can any one tell me the steps to delete a class using destructiveChanges.xml
- Fulfill the PreRequisites for using the Force.com Migration tool
- Install the Java JRE/ JDK
- Install Apache Ant
- Copy the
ant-salesforce.jarfile from the unzipped file into the ant lib directory.
- Follow the steps at Apex deploying using Ant to understand the basic setup
- Construct your
destructiveChanges.xmlfile using Propagating Destructive Changes
<?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <fullName>codepkg</fullName> <types> <members>SampleDeployClass</members> <members>SampleFailingTestClass</members> <name>ApexClass</name> </types> <version>26.0</version> </Package>
Run the Force Migration tool
Here's a Video Tutorial
From this blog
To achieve this via Workbench, create a folder on your desktop. I will call my folder ‘deleteClasses’.
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="http://soap.sforce.com/2006/04/metadata"> <version>30.0</version> </Package>
- 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="http://soap.sforce.com/2006/04/metadata"> <types> <members>SomeClass</members> <name>ApexClass</name> </types> <version>30.0</version> </Package>
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 row into the file with the name of the other class, for example:
<?xml version="1.0" encoding="utf-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>SomeClass</members> <members>SomeOtherClass</members> <name>ApexClass</name> </types> <version>30.0</version> </Package>
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.
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.
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.
Select Migration > Deploy.
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.
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.
Using force.com migration tool with ANT allows you to deploy destructivechanges.xml. http://www.salesforce.com/us/developer/docs/daas/index.htm
The sample package provided includes a destructive changes example.
Advantages of using this over doing it straight from Eclipse are:
- You can replicate the operation against different sandboxes /
production by running the script again. So for example you can first
test that the destructive deploy works as you want in a UAT
environment and then run the script connecting to production.
- You don't tie up your eclipse waiting for a response (for a big org a production deploy takes significant time)
The fastest way to do this is by adding your Production org in Force.com IDE / Eclipse and delete the class via the IDE. You will have to make sure that no dependencies exist before deleting, else the delete will fail.
Remove the dependencies by deleting the class first in your sandbox, then seeing why the delete would fail, do those changes, deploy it to your production org, then delete the class via Eclipse
Edit: You could also use the Force.com Migration Tool with Apache Ant to make desctructive changes, however this takes a little coding and installing ant and generally takes a little longer to set up compared to the eclipse method if you only need to do this a few times. more about that here: http://wiki.developerforce.com/page/Propagating_Destructive_Changes