Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by James Loghry, Samuel De Rycke, mast0r, sfdc_ninja, Bartley Jan 1 at 15:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Look at question Deleting Triggers/Classes from Production. –  Peter Knolle Dec 30 '13 at 22:22

4 Answers 4

up vote 8 down vote accepted

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

share|improve this answer
  1. from Setup > Create > Packages, create a new Package in your org

  2. add the components to it using the UI

  3. run ant pull -Dsf.username=user@example.com.dev -Dsf.password=secret

  4. 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>
    
  5. run ant push -Dsf.username=user@example.com.dev -Dsf.password=secret

  6. 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>
share|improve this answer

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.

share|improve this answer

Very easy to do.

  1. Open Force.com IDE
  2. Get contents of production
  3. Find the class or trigger xml file
  4. Change Active/Inactive to Deleted
  5. Save

This will delete the class from production as long as the unit tests do not fail due to its deletion.

share|improve this answer
    
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 K Apr 22 at 13:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.