Deleting Triggers/Classes from Production

  • I was recently told ( Deleting a Class with IDE - cannot delete from Production? ):

    You cannot delete a class in production directly. You will need delete the class from your sandbox and then deploy the deletions to your production org. When you deploy from sandbox to production, the missing classes will come up in red and you can choose to deploy these deletions to Production.

    However, I'd like some clarification because finding information on how to do this is like pulling teeth, unfortunately. Am I supposed to:

    1. Delete the Trigger in Sandbox
    2. Make a deployment package in Sandbox
    3. Add the Trigger which is going to be listed in RED now
    4. Deploy (and that deletes it from Production)?

    I am not seeing deleted Triggers in Red in Sandbox. Are they NOT listed under "Triggers" for deployment, but elsewhere? Frustrated = true. Does this ONLY apply to Classes??

    UPDATE: I just tried again, with a CLASS, and it still doesn't show up at all as a Deployable package (red or not) after I delete it in the Sandbox.

    UPDATE 2: I was just able to delete a class, that I know was written via IDE from a third party, in both Sandbox and Production. So now I'm wondering if it has to do with where it was originally deployed from (if from IDE, IDE can delete it - it from Sandbox, you have to jump through hoops). :-(

  • An easy way to do this is as follows:

    1. Use an IDE to create a new project and download all classes from production.
    2. In the class you want to delete, open the metadata file and change the status of the class to "deleted".
    3. Save to the server.

    Observe the status of the class in the example below:

         <?xml version="1.0" encoding="UTF-8"?>
         <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
             <apiVersion>23.0</apiVersion>
             <status>Deleted</status>
         </ApexClass>
    

    You should try this in sandbox and become comfortable with it before attempting it in production. Double-check the class name before deleting.

    Salesforce Documentation

    I shall try this. Good Lord, I hope it's this simple...

    This works flawlessly. Thanks so much. I can finally get rid of about 10 classes and 20 triggers that have previously only been "commented out". :)

    Mohith, you're the man.

    I tried the above method, but when I save / deploy to production it resyncs from the service and overwrites 'Deleted' to 'Active'.

    @PaulFischer This may be due to reason that there is some dependency of the class and thats not letting you to delete the same .Try deleting in sandbox to undertand dependency

    BTW, a simple way to delete multiple classes/triggers, is to uncheck Build Automatically from the Project menu. Change the status to Deleted and save for each. Then, Highlight the metadata file for each (Ctl-Click), right-click and Save to Server. It will run all Test Classes, but only once instead of once for each trigger/class.

    This solution is missing the destructiveChanges.xml which can have the same contents of package.xml. Still need to zip the folder with the "Deleted" status, destructiveChanges.xml & package.xml

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used