Deleting Triggers/Classes from Production

An easy way to do this is as follows:

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

Salesforce Documentation


From this blog

  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>
  1. 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 into 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.


If you are using VS Code you can remove the classes and triggers using Terminal command.

  1. Find the class/trigger that you want to delete and change the metadata for status to be Deleted.

  2. You will need to specify the name of the class/trigger in the sfdx force deploy command, and also you can delete multiple class/triggers per command (you will separate them with ,)

Here is example of the command:

sfdx force:source:deploy -m ApexClass:name_of_the_class,ApexClass:name_of_the_class2,ApexTrigger:name_of_the_trigger -l RunLocalTests -u AliasOfTheProject