Delete Apex Class from Salesforce using workbench

Many times we wish to deactivate or delete Apex class from Salesforce. While I have always relied on Eclipse for this, I came across this method using workbench. For those, who would rather not download the heavy Eclipse and go all the way to install force.com plugin.

Let’s say I have a trigger called ‘UpdateAmount’ which is calling the class ‘Amtupdate’.

Note: you would require Admin privileges on your Salesforce account for this operation to succeed.

First open notepad and copy the following code:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>UpdateAmount</members>
        <name>ApexTrigger</name>
    </types>
    <version>45.0</version>
</Package>

You can replace the version with your API version or leave it as it is.

Save the file as package.xml.

Open workbench.developerforce.com and click on Migration->Retrieve. Note: If you have not already logged in your Salesforce account, workbench will ask you to login and ask your permission to allow access to your environment.

Upload the package.xml file that you just created to Unpackaged Manifest. Click Next.

WorkbenchDelete Apex trigger using workbenchScreenshot

Click on Download Zip File below the results box.

Delete Apex trigger using workbench

Extract the Zip file. Go to triggers folder. Open UpdateAmount.trigger-meta in notepad. Replace line <Status>Active</Status> with < Status>Inactive</Status> or Status>Deleted</Status>

Save the file.

Come out of Triggers folder. Select Triggers folder and package.xml and right click-> Send to Compressed (Zipped) folder.

Go back to workbench. Click on migration->Deploy. Upload the newly created package.zip to workbench.

Delete Apex trigger using workbench

Click Next->Deploy. It should show success: true in results page. That’s it you have successfully deleted or deactivated the trigger. Note if your trigger is calling a class, you should first delete the class and then the trigger. Safest is to deactivate the trigger, make sure no functionality is being affected and than delete the class and trigger.

Leave a Reply

Your email address will not be published. Required fields are marked *