function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Heather Hicks 16Heather Hicks 16 

Deleting apex classes/triggers via Workbench?

I've read many postings about using Eclipse with the Force.com IDE to orchestrate the deletion of Apex triggers and classes in production. However, within the Developer Workbench (Info-->Metadata Types & Components), I can select my class or trigger, hover over its Id, and delete the object. When I do this in my sandbox, I can confirm that the class and trigger were indeed deleted (that is, they aren't visible any longer in the UI). Is it possible that deleting classes and triggers can be this simple in Production? I feel like this is a trap! By the way, I did confirm that when I log into the workbench attached to my prod environment, I *do* still have the delete option. I'm just nervous to pull the, um, trigger. Has anybody tried this? What, exactly, am I deleting? 
NagendraNagendra (Salesforce Developers) 
Hi Heather,
  1. To achieve this via Workbench, create a folder on your desktop. I will call my folder ‘deleteClasses’.

  2. Then go to Notepad (or another text editor) and copy and paste the below and save as the file with ‘package.xml’ and ‘All files (.)’.

    <?xml version="1.0" encoding="UTF-8"?>
    
    <Package xmlns="http://soap.sforce.com/2006/04/metadata">
    
    <version>30.0</version>
    
    </Package>
  3. Then create a new file in Notepad (or another text editor) and copy the below into it:
<?xml version="1.0" encoding="utf-8"?>

<Package xmlns="http://soap.sforce.com/2006/04/metadata">

<types>

<members>SomeClass</members>

<name>ApexClass</name>

</types>

<version>30.0</version>

</Package>
Replace SomeClass with the name of your class that you wish to delete. If you have two classes that need to be deleted at the same time, you can simply add another row to the file with the name of the other class, for example:
<?xml version="1.0" encoding="utf-8"?>

<Package xmlns="http://soap.sforce.com/2006/04/metadata">

<types>

<members>SomeClass</members>

<members>SomeOtherClass</members>

<name>ApexClass</name>

</types>

<version>30.0</version>

</Package>
  1. Save this file name as destructiveChanges.xml (note the capital ‘C’ in ‘changes’). Make sure the file is saved as ‘All files (.)’. More information on destructive changes can be found here.

  2. Now there are two files in your folder. Open the folder, select both the XML files, right-click and select ‘Send To > Compressed Folder’. Keeping the default name of ‘package’ for the folder is fine.

  3. You are now setup to deploy the destructiveChanges.xml file to Salesforce. To do this, go to Workbench and login with your credentials. It is recommended that you login to a Sandbox instance before you deploy the file to production.

  4. Select Migration > Deploy.

  5. Click ‘Browse’ and select the .zip package file. Then check ‘Rollback on Error’, ‘Single Package’, and select Test Level with ‘RunLocalTests’. More information on the Test Level can be found here.

  6. Finally, select ‘Next’ and then you will notice that the success or error results will be displayed in Workbench once the deployment process has been completed.

This is a very easy way to delete Apex classes and can be very handy if you need a lightweight tool to do the job.

Hope this helps.

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra 



 
Heather Hicks 16Heather Hicks 16
Nagendra, thanks so much for the thorough instructions. Do you know, though, what would happen if I simply selected 'Delete' from within Workbench, as I described? 
Kamal ThakurKamal Thakur
Yes @heather, you can delete that via Delete Button too.
Jenn Rudiger 14Jenn Rudiger 14
Nagendra, thanks so much for this. Great instructions.
chandra v 14chandra v 14

Please check the blog post below for step by step procedure

https://www.forcetalks.com/blog/deleting-apex-classes-apex-triggers-from-production-using-workbench-salesforce-tutorial/

Thanks!