+ Start a Discussion
GMASJGMASJ 

Delete trigger in production

We have some unused trigger some of active and inactive in production is there a way to delete a trigger in production. 

Thanks
GMASJ
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

It is not possible to directly delete an Apex class or trigger after it has been deployed to production. A quick workaround to delete or disable Apex Class/Trigger is by using eclipse and Force.com IDE.

Follow the below steps:

1. Assuming you have a sandbox environment synchronized with your Production org, you will first want to deactivate the trigger in sandbox. You can refresh your IDE project to consume these changes.

2. In the Sandbox org, you will then want to run all tests: Navigate to Setup | Develop | Apex Classes and click 'Run All Tests.' This will run all of the tests in the sandbox org. This is an important step to validate whether or not the inactive trigger has impacted any asserts within your test methods. Assuming this behavioral change has impacted your tests, you will need to update your asserts to reflect this.

3. Once all tests are passed, you can now deploy these changes to your production environment. You can use the Deploy to Server wizard in the IDE. Simply select the tests that you have modified, as well as the inactive trigger, and deploy these changes to your production environment.

4. Validate if the trigger is now inactive in your production environment.
Delete the trigger (if necessary - an inactive trigger will not fire and therefore can be considered as "soft deleted")

5. Create a new IDE project against your Active production org.

6. Right click on the specified trigger and select delete. Accept the option to delete from server. Since the trigger is inactive - it can now be deleted from the production environment.

Please refer to the below links which might help you further with the above requirement.

https://help.salesforce.com/articleView?id=000324024&language=en_US&type=1

https://sfdcfanboy.com/2017/11/24/a-tip-a-day-24-3-ways-to-delete-an-apex-class-from-production/

https://www.salesforceben.com/way-to-delete-apex-classes-from-production/

https://www.simplysfdc.com/2016/12/salesforce-delete-trigger-and-apex.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi GMASJ,

It is not possible to directly delete an Apex class or trigger after it has been deployed to production. A quick workaround to delete or disable Apex Class/Trigger is by using eclipse and Force.com IDE.

Here are the steps –

Download Force.com IDE.
Connect to the salesforce production org.
Download the apex class/trigger.
Open the XML file of the Apex class/trigger.
Change the status of the Apex class/trigger to Deleted.
Save and deploy to server.

Note – Apex class status can only be changed to “Active” or “Deleted” and not “Inactive”.
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Ravi Dutt SharmaRavi Dutt Sharma
You need to use Ant to delete any code component from Production. You need to use a destructiveChanges.xml file and deploy it.

More details here: https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/daas_destructive_changes.htm
Tad Aalgaard 3Tad Aalgaard 3
Use this link that Khan listed.

https://www.salesforceben.com/way-to-delete-apex-classes-from-production/

It's by far the easiest way to do delete triggers and apex as you don't have to install Eclipse / Force.com IDE (which is the hardest way possible to do this).