Salesforce allows you delete some components directly in Production but not all. Components like Apex Classes, triggers can not be deleted directly in Production.
Lets say you have your Salesforce org and you want to delete a class with name lets say ‘AccountController’. Follow below steps:
- Create a folder in your desktop. Lets say ‘deleteComponents’.
- In your notepad copy paste below code and save the file as ‘package.xml’ in deleteComponents folder
<!--?xml version="1.0" encoding="UTF-8"?--> <package xmlns="http://soap.sforce.com/2006/04/metadata"> <version>56.0</version> </package>
- Create another file with below code and save the file as ‘destructiveChanges.xml’ in deleteComponents folder.
<?xml version="1.0"encoding="utf-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>AccountController</members> <name>ApexClass</name> </types> <version>56.0</version> </Package>
- Select two XML files (destructiveChanges.xml and package.xml) from deleteComponents folder and convert them to compressed folder. Keep the default name of the compressed folder.
- All the setup for destructive change is ready.
- Go to workbench and log in using your Salesforce org credentials.
- Go to Migration and select Deploy.
- By clicking on Browse button, select compressed file.
- Check ‘Rollback on Error’, ‘Single Package’, and select Test Level with ‘RunLocalTests’.
- Click Next and deployment will begin.