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.

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). :-(

share|improve this question
add comment

3 Answers

up vote 14 down vote accepted

An easy way to do this is as follows:

  1. Use 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 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 technique in sandbox and become comfortable with it before attempting in production. Double-check the class name before deleting.

share|improve this answer
    
I shall try this. Good Lord, I hope it's this simple... –  AMM Dec 28 '12 at 15:56
2  
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". :) –  AMM Dec 28 '12 at 16:11
    
thanks and enjoy!! –  Mohith Kumar Dec 28 '12 at 16:17
    
Mohith, you're the man. –  JannieT Nov 26 '13 at 16:39
add comment

The way I've deleted triggers/classes from production is to delete the trigger/class from the sandbox and then deploy the triggers/classes folder. When you do that, eclipse will present you with the diffs between the source (sandbox) and target (production) and the deleted classes/triggers will be displayed there.

You can't deploy a deleted trigger/class in isolation, as it doesn't exist in the sandbox and thus there is nothing to deploy.

share|improve this answer
    
I'd like to add to this, but I had issues when I did this when deleting from Eclipse because I also told Eclipse to delete from the server as well as locally. When you delete from Eclipse locally, you don't want to actually delete from server in the Sandbox when you do that. If you do, it will actually delete the metadata that refers to it also locally and then doesn't allow you to deploy it. –  dphil yesterday
add comment

Using Eclipse, from a Sandbox project:

  1. Make a list of components to delete.
  2. Select all Classes, Triggers, Pages, or other Metadata components to delete.
  3. Right click on one of the selected components and click Delete in the menu.
  4. When prompted, click Yes to delete the component from the Server (Salesforce Sandbox). This will result in the components being removed from the Sandbox and from your local project in eclipse.
  5. Once the delete finishes, right click on the "src" directory in the project and click Force.com > Deploy to Server in the menu.
  6. Enter the credentials for your destination organization (another Sandbox, Developer Edition, or Production) and click the Next button until you get to the Deployment Plan part.
  7. IMPORTANT: Click the Deselect All button.
  8. Scroll until you reach the Delete action section.
  9. Check the box next to all components to delete (in your list).
  10. Click Next to deploy.

I recommend deploying the delete to another sandbox to confirm that everything works well before deploying to production. If done correctly, this process will delete all selected components from the destination organization.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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