Delete Apex Classes/Triggers from Production Using Workbench

May 03, 2023


 

This blog is explained How can we delete apex classes or triggers from Production Salesforce Org.

As we know we cannot delete the apex classes or triggers from Salesforce Production org directly unlike the sandbox salesforce orgs. So How can we do this? Yes, it is possible using a workbench. So, let us do it by practically with the help of the following steps:

 

Step 1:

First create a folder on your desktop named Delete Classes.

To delete classes, first we need to create two xml files and save these files in your newly created folder. Make sure that your files are saved as All files(.).

 

Save this file as package.xml

              <!--?xml version="1.0" encoding="UTF-8?-->

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

              <version>45.0</version>

              </package>

 

Save this file as destructiveChanges.xml where C is the capital in destructiveChanges:

              <?xml version="1.0" encoding="utf-8"?>

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

              <types>

              <members>ClassName</members>

              <name>ApexClass</name>

              </types>

              <version>45.0</version>

              </Package>

 

If you want to delete more than one class or trigger, you can add class name or trigger as shown below:

              <?xml version="1.0" encoding="utf-8"?>

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

              <types>

              <members>ClassName</members>

              <members>SomeOtherClassName</members>

              <members>SomeOtherClassName</members>

              <members>SomeOtherClassName</members>

              <members>SomeOtherClassName</members>

              <name>ApexClass</name>

              </types>

              <types>

              <members>TriggerName</members>

              <members>SomeOtherTriggerName</members>

              <members> SomeOtherTriggerName</members>

              <members> SomeOtherTriggerName</members>

              <members> SomeOtherTriggerName</members>

              <name>ApexTrigger</name>

              </types>

              <version>45.0</version>

              </Package>

 

Important: Please change the version according to your salesforce org version.

 

Step 2:

Now go back in your folder and select both xml files and right click then select Send to > Compressed (zipped) folder.

Accept name as package zip file.

 

 

You should get the file name as package as show in the below figure:

 

 

Notes to remember: If you made changes in package.xml or destructiveChanges.xml or both then you need to create a new package.zip file again.

 

Step 3:

We are now set up to deploy the destructiveChanges.xml file to Salesforce. 

Go to Workbench and login with your credentials and follow these steps: -

  1. Select Migration > Deploy

 

 

  1. Select the package.zip file that we create in the above steps.
  2. Then check Rollback on ErrorSingle Package and select the Test Level with RunLocalTests.

 

 

  1. Click on the Next button and then click on Deploy button.
  2. After that we will see Success or Error results in Workbench if the deployment process has been completed.

 

However, we can delete the apex classes or triggers from Salesforce Production Org.

 

 

I hope this blog helped you!