+ Start a Discussion
Nicole YoungNicole Young 

How do I delete an apex trigger from production?

Best Answer chosen by Nicole Young
Jeremiah DohnJeremiah Dohn
The easiest way I have found is to use developer workbench and a package.xml file.

Steps:

1. Create a package XML file (replace your trigger name below):
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>YOUR TRIGGER NAME HERE</members>
        <name>ApexTrigger</name>
    </types>
    <version>32.0</version>
</Package>

2. Go to the developer workbench:
https://workbench.developerforce.com/

3. Click on the "Retrieve" section on the top, choose your package XML file created and then submit.

4. In your downloaded package.xml file, click on the XML data file and change the status from "Active" to "Deleted."

For more information on package.xml files:
https://www.salesforce.com/us/developer/docs/api_meta/Content/manifest_samples.htm

For metadata types useable with this download format:
https://www.salesforce.com/us/developer/docs/api_meta/Content/meta_types_list.htm

For trigger metadata attributes:
https://www.salesforce.com/us/developer/docs/api_meta/Content/meta_triggers.htm

It goes without saying, please be very careful when doing this process and always make sure that you are in the appropriate org in workbench before doing these types of updates.  You can see where you are at by hovering over the company name in the upper right-hand corner.

If this answer is helpful to you, please mark as the best answer to assist others that may have this issue.

All Answers

Nash ZgonjaninNash Zgonjanin
Here you go. Article from Help

https://help.salesforce.com/HTViewSolution?id=000006188&language=en_US

How to Disable or Delete an Apex Class or Trigger from a Production Org
Knowledge Article Number: 000006188 

Description- An Apex class or trigger must be removed from a production instance if it is blocking a deployment or is no longer needed.
- Apex code may not be modified directly within a Production org, so it requires a couple of steps using Developer tools.
- This article gives instructions using the Force.com IDE
- This is the only way an Administrator or Developer can disable or remove Apex in a Production org.


Resolution- Force.com IDE should be installed and working.
- Connect to the Sandbox Instance using the IDE and find the class or trigger that you want to delete.
- Open the matching .xml file change the Status XML tag from "Active" to "Deleted" if you want to remove the trigger or class, or to "Inactive" if you want to disable the trigger.
- Apex class Status can only be changed to "Active" or "Deleted", not "Inactive".
- Save the file.
- Select the two files (Code and XML) using Ctrl-click, then right click on one of them. Select Force.com > Deploy to server.
- Provide your credentials for the production org and follow the steps.
Nicole YoungNicole Young
What if there isn't a corresponding trigger in the sandbox for the one I'm trying to delete? 
Jeremiah DohnJeremiah Dohn
The easiest way I have found is to use developer workbench and a package.xml file.

Steps:

1. Create a package XML file (replace your trigger name below):
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>YOUR TRIGGER NAME HERE</members>
        <name>ApexTrigger</name>
    </types>
    <version>32.0</version>
</Package>

2. Go to the developer workbench:
https://workbench.developerforce.com/

3. Click on the "Retrieve" section on the top, choose your package XML file created and then submit.

4. In your downloaded package.xml file, click on the XML data file and change the status from "Active" to "Deleted."

For more information on package.xml files:
https://www.salesforce.com/us/developer/docs/api_meta/Content/manifest_samples.htm

For metadata types useable with this download format:
https://www.salesforce.com/us/developer/docs/api_meta/Content/meta_types_list.htm

For trigger metadata attributes:
https://www.salesforce.com/us/developer/docs/api_meta/Content/meta_triggers.htm

It goes without saying, please be very careful when doing this process and always make sure that you are in the appropriate org in workbench before doing these types of updates.  You can see where you are at by hovering over the company name in the upper right-hand corner.

If this answer is helpful to you, please mark as the best answer to assist others that may have this issue.
This was selected as the best answer
Nash ZgonjaninNash Zgonjanin
Refresh your sandbox and you will have trigger in sandbox after that.
Nicole YoungNicole Young
Thank you Jeremiah! The workbench worked.
Rob Nelson 8Rob Nelson 8
Hi Jeremiah. I changed the trigger-meta.xml to be inactive. 
 
<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>38.0</apiVersion>
    <status>Inactive</status>
</ApexTrigger>

But not sure about the next step. Do I use the Workbench > Migration > Deploy? 
Jeremiah DohnJeremiah Dohn
That's correct Rob.  You need to deploy the changes back to the organization.
Sarah Taylor 6Sarah Taylor 6
I am following you since 2015 January I got lots help form your website actually I am providing Help With Dissertation Writing (http://www.Dissertationhouse.co.uk/) I always prefer your site to students and just want to say two words for you “Thank You”.
Evan ZhangEvan Zhang
Hi Jeremiah,

When I try to retrieve the XML document, I get this error:

'version' element is required

Is there something that I'm missing here?
Jeremiah DohnJeremiah Dohn
That means that you're missing the version element in the package.xml file.  Please see the above properly formatted package.xml file.  The current API version is 38 if you're on Winter '17 or 39 if you're on Spring '17 (I'd go with v38 to be safe).
Evan ZhangEvan Zhang
This is what I have, I've added the 38.0 version and still getting that error. Am I formatting it wrong?

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>NumberContacts</members>
        <name>ApexTrigger</name>
    </types>
    <version>38.0</version>
</Package>



Thanks! 
Jeremiah DohnJeremiah Dohn
Are you zipping the file for your retrieve via workbench or are you retriving via ant?  The actual formatting of your file appears to be correct.  You may need to change it to version 37.0 for your retrieve if you are using workbench since they do not have v38 available there yet.
sfdcFanBoysfdcFanBoy
There are a number of ways to stop a trigger to run.  I've consolidated the list.  Read here
https://sfdcfanboy.com/2017/11/23/a-tip-a-day-23-5-ways-to-stop-trigger-in-production/ 
Amy ColinAmy Colin
Jeremiah:  In Step 1 above where you say "Create a package XML file."  What is that and how exactly do I do that?  I'm an admin with no developer experience, and I didn't quite understand the information in the link you shared for more information on package XML files.  Thanks for any direction you can give me!
Rahul Singh 1474Rahul Singh 1474
Interesting post i have been wondering about this issue, so thanks for posting. Pretty cool post. It’s really very nice and Useful post. Thanks. http://www.axivasichem.com/
 
David Roberts 4David Roberts 4
... it won't delete!:
I had a visualforce page, apex class and apex test class to delete.
I attempted to delete them in three stages:

I created the package file with just the test class.
I retrieved the package and then edited the class meta data files to change Active to Deleted.
I then zipped it back (called it repackaged.zip) and deployed it using "Rollback On Error", "Single Package" and "Run local tests".
This deleted the test class.

I then went to setup in salesforce, found the Visualforce page and deleted it. (otherwise, class is dependent and can't be removed). OK.

I changed the package file to list the active class, retrieved it and changed the meta data to 'Deleted'. Zipped and deployed as above but it won't delete. It doesn't say why.
Frustrating...
David Roberts 4David Roberts 4
I took a deep breath then went back to basics:
I used the "destructiveChanges.xml" method.
See 
http://www.salesforceben.com/way-to-delete-apex-classes-from-production/
https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/daas_destructive_changes.htm

First made sure I'd deleted the visualforce page that called the controller.

When I deployed my changes, I got an error saying my class had been used in a lightning bundle.
How do I put a lightning bundle into the destructiveChanges xml?
Turns out, there's no need.
I ran the Dev Console from production, opened the offending bundle and was able to delete it via the file menu.
I checked and, yes, it had gone.

I then deployed my package again and succesfully removed my class and test class.
Happy again! :)
PSA - Francis HuangPSA - Francis Huang
You can use ClickDeploy to point-and-click deploy items without having to manually edit xml files.
https://app.clickdeploy.io/

Create a deployment package and go to the Deploy Options tab, Change button, Deploy Type: Destructive, and Save.
Then add the items you want to delete to to the deployment package and click Deploy.
Blog article explaining this method:
https://medium.com/@clickdeploy_team/delete-apex-classes-from-production-3c66306f1a0e
spring maidsspring maids
The good news is lot about work that ought to be done to ensure if you have a building is normally fit just for tenancy. The governing of Dubai could be very particular in the case of quality for the indoor environment from the building. For that matter, the governing has a requirements specifically fond of the repairs and maintenance of work sites as soon as completion from the project. cleaning services in dubai (https://www.springcleaning.ae/)