How do you delete or deactivate the apex classes / triggers on your Salesforce Production Org? Unfortunately, it is not as simple as going to the Apex class and hitting the delete button or unchecking the ‘Active’ checkbox.
For deleting or disabling the code, you can take one of the following two routes:
1. Probably the simplest way to delete / disable is to connect to your Salesforce production org from VS Code download the apex class / trigger, change the status of the Apex class / trigger to “Deleted” or “Inactive” in the class/trigger XML file and save. In this step-by-step guide we are going to cover this method.
2. The 2nd way is to use ANT Migration tool and here is the link to a knowledge article http://help.salesforce.com/apex/HTViewSolution?id=000006188&language=en_US on how to use this method.
(If you are not familiar with ANT Migration tool here is just the guide you need – Step-by-Step Guide on Getting Started with Salesforce ANT Migration Tool)
NOTE: Certain sections of the guide will appear as locked in the free preview. You can download the unlocked version of the guide in PDF format by subscribing to our “All Access” Pass through the link below.
Everything worked until we tried to ‘Deploy Source to Org’. The Problems log is empty. Can’t attach screenshot
Hi Milad, it will be a bit difficult to troubleshoot without knowing any further details. One thing that you may want to check is whether your user has the “Author Apex” permission in the org. The other option will be to log a case with Salesforce support and get their help.
SF Support sent me to this article
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_deleting_files.htm
Ok, so you will need to use ANT Migration Tool for this. Here is a step-by-step guide on that also if you are interested – https://www.asagarwal.com/step-by-step-guide-on-getting-started-with-salesforce-ant-migration-tool/
This will run test classes and check code coverage right prior to delete.
Everything here worked until ‘deploy source to org’ which fails for both classes and triggers. What could be wrong?
Hi Sara, what was the error that you got while deploying? Can you share any screenshot?
Hi, how to disable triggers by ANT? Could you provide a step-by-step guide? Thanks.
Maybe this is a little bit late, but the easiest way is to use Custom Labels with a True/False value that you reference in your trigger logic
I followed the slide show exactly, changed the xml for the the metadata fro active to deleted, and checked in Salesforce and the Apex classes were still active. Do you have a further solution or idea as to why this is not working?
Thank you! Step 1 worked perfectly for me. The slideshare was also very helpful as I was not very comfortable in Eclipse. Thank you again! Dan
Hi Sam, once you save the changes, can you log on to to your Salesforce org in the browser and check the status of the trigger/apex class there. The changes should be reflected there.
This doesn’t work. When you save the XML file it just changes the status back to “Active”.