How to remove Apex Code from Production Environment

By | July 21, 2021

It is fairly effortless to delete an unwanted apex class or trigger in a Sandbox Environment. On the other hand, Unlike the Sandbox environment, it is not possible to delete code from Production environment just by clicking in the DELETE Button. Here are some methods that may work for you. NOTE: Please consider that deleting or removing code from Production affects the code coverage of the Org. Ensure that the coverage is above 75% which is the salesforce standard.

Comment the Code

The easiest way would be to comment the code. This method obviously doesn’t delete the apex class but it is a relatively quick fix. The code is commented in the Sandbox Environment and deployed to Production.

Comment Class
Comment Class

Using Workbench

We are going to delete MyRestResource.apxc

All Classes
All Classes
  • Create an xml file and save it as package.xml.
  • Enter the following snippet into the xml file and save it. (If required update the version to the latest one).
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>51.0</version>
</Package>
  • Create another file, copy the below text and save it as “DestructiveClasses.xml”. to delete multiple files, add more <members> nodes and update the class name into the nodes. To delete triggers, add a <types> node and enter <name> as ApexTrigger.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<version>51.0</version>
<types>        
<members> MyRestResource </members>        
<name>ApexClass</name>
</types>
</Package>
  • Save the two files and zip them together. Name the zip file as package.zip.
  • Login to Workbench and select Migration and go to Deploy, upload the zip file and enable ‘Rollback On Error’, ‘Single Package’ and ‘Check Only’. Click next and deploy.
Workbench Setup
Workbench Setup
  • If the validation is Success, Uncheck the “Check only” checkbox and continue the deployment.
Success Message
Success Message
  • Once you receive the success message, the class will be deleted.
Class Deleted
Class Deleted

Using the steps mentioned in the blog above, we hope you are able to extract the code from Production org of your Salesforce.

We hope you may find this blog resourceful and helpful. If you still have concerns and need more help, please contact us at salesforce@greytrix.com.

About Us
Greytrix – a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.

Greytrix has some unique solutions for Cloud CRM such as Salesforce Sage integration for Sage X3Sage 100 and Sage 300 (Sage Accpac). We also offer best-in-class Cloud CRM Salesforce customization and development services along with services such as Salesforce Data MigrationIntegrated App developmentCustom App development and Technical Support business partners and end users.
Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU™ integration for Sage ERP – Salesforce is a 5-star rated app listed on Salesforce AppExchange.

The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.

For more information on our Salesforce products and services, contact us at salesforce@greytrix.com. We will be glad to assist you.

Related Posts