We currently have around 20 apex classes and 5 triggers which are not used in our production org. We want to delete them in our production instance. We dont have ant scripts ready yet to be used for our deployments and so we cannot use destructivechanges file. Currently our production deployments are done by our support team and they need documentation from us to do these deletes. Changesets do not allow to delete apex classes and triggers. So what is the best way to delete these apex classes and triggers from production?
4 Answers
You have a few options. My recommendation however, will be to use ANT and destructiveChanges.xml contrary to your post. It might take a few hours to set ANT up in your environment and in your support team's environment, but it is a repeatable process you can run on multiple orgs if need-be.
Running the ANT script (can) be easier for your support team rather than manually deleting the classes and triggers or installing eclipse on their local machines and deleting the files that way.
If you really want to get crazy with it, and simplify it for your support team, you could even set up a CI tool that would allow a push button delete of the classes, which would fire the ant migration toolkit script to delete the files from a designated org.
More info on the destructiveChanges approach is here: http://wiki.developerforce.com/page/Propagating_Destructive_Changes
and
How to delete a class from production using destructiveChanges.xml
from Setup > Create > Packages, create a new Package in your org
add the components to it using the UI
run
ant pull [email protected] -Dsf.password=secret
update
EachOfYourClasses.cls-meta.xml
to read<status>Deleted</Status>
, eg:<?xml version="1.0" encoding="UTF-8"?> <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> <apiVersion>29.0</apiVersion> <status>Deleted</status> </ApexClass>
run
ant push [email protected] -Dsf.password=secret
delete the Package from your org
Here's the build.xml you will need:
<project default="usage" basedir="." xmlns:sf="antlib:com.salesforce">
<property environment="env"/>
<target name="pull" description="Retrieves all package components">
<sf:retrieve
username="${sf.username}"
password="${sf.password}"
serverurl="https://test.salesforce.com"
retrieveTarget="src"
packageNames="deletions" />
</target>
<target name="push" description="Deploys all package components">
<sf:deploy
username="${sf.username}"
password="${sf.password}"
serverurl="https://test.salesforce.com"
deployRoot="src" />
</target>
</project>
Although not really recommended and "at your own risk" the Force.com IDE allows you to select and delete a class in production. You would need to identify dependencies first and this would only work if no dependencies existed. It's essentially an ANT destructive change on a single file and will trigger all tests to run. Assuming your tests pass, the delete will succeed.
Another option is to burn a new sandbox, start a new project for that sandbox in the Force.com IDE, delete your apex class in the sandbox, run tests to make sure your delete didn't muck up your instance, and deploy the entire classes folder, including deletions.
Very easy to do.
- Open Force.com IDE
- Get contents of production
- Find the class or trigger xml file
- Change Active/Inactive to Deleted
- Save
This will delete the class from production as long as the unit tests do not fail due to its deletion.
-
Also, you can select multiple components (for example: a Visualforce Page, a Class, etc.) and delete using Eclipse. Deleting one at a time could be a very time consuming process!!– Matt KCommented Apr 22, 2014 at 13:31