Production Operations : Deactivate/Delete the Apex Class/Triggers with Best Ways
DEACTIVATE THE TRIGGER AND CHANGES INTO CLASS
1. Active Check Box : This is the simplest way to do of all is Deactivate your trigger in your sandbox by unchecking the Active checkbox of the trigger.Create an outbound change set, upload and deploy the change set to production.
2. Comment Code : The other simpler way is comment your entire apex trigger code in your sandbox and then use outbound change set to deploy to production. To comment code, you need to use /* and */ . Anything in between those will be commented and this method is also used for Apex class.
trigger ContactTrigger on Contact (before insert){
/*
your entire code
*/
}
3. FROM CUSTOM SETTINGS : You can control whether a trigger should run or not. Create a custom setting (Trigger_Config__c). Add a checkbox field “Is Active” and Text field for Trigger Name and its status in IsActive checkbox control all process.
Apex trigger, add an IF condition at the top to check if the Trigger status in Custom settings is TRUE, only then run the entire apex trigger code.
trigger ConTrigger on Contact (before insert){
Trigger_Config__c TC = Trigger_Config__c.getValues(‘ContactTrigger’);
if(TC.is_Active__c == TRUE){
//your trigger code
}
}
You can control turn off the trigger in production, You just need to go to your custom settings and uncheck the IsActive checkbox for that trigger.4. USE ECLIPSE IDE : InActive in the trigger’s XML file and then deploy from Eclipse.
- First install Force.com IDE
- Connect to the Sandbox Instance using the IDE and identify the trigger that you want to deactivate.
- Open he trigger’s .xml file, and change the Status XML tag from Active to Inactive.
- Save the file.
- Select Force.com and Deploy to server.
- Provide your credentials for the Production org and follow the steps.
Example: (Trigger)
<?xml version="1.0" encoding="UTF-8"?>
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>36.0</apiVersion>
<status>Active</status>
</ApexTrigger>
Example: (Class)
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>31.0</apiVersion>
<status>Deleted</status>
</ApexClass>
5. USE WORKBENCH : 1. To do this using Workbench, create a folder in your PC. example: ‘deleteFromSalesforce’.
2. Go to Notepad 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/2008/04/metadata">
<types>
<members>class to Delete</members>
<name>ApexClass</name>
</types>
<version>41.0</version>
</Package>
For Multiple Class use below Code with Tag row into the file with the name of the other class, for example:
<members>class1 to delete</members>
<members>class2 to delete</members>
4. Save the file with name as destructiveChanges.xml (note the capital ‘C’ in ‘changes’). Make sure the file is saved as ‘All files (*.*).5. Open the folder, select both the XML files, right-click and make it compression ‘Send To > Compressed Folder’. Keep the default name of ‘package’ for the folder .
6. You are now setup to deploy the destructiveChanges.xml file to Salesforce. To do this, go to Workbench and login with your credentials.
7. Select Migration > Deploy.
8. Click ‘Browse’ and select the .zip package file.
Then check ‘Rollback on Error’, ‘Single Package’, and select Test Level with ‘RunLocalTests’.
9. Now, 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.
Hope its help you...
Comments
Post a Comment