Things to Consider Before Deactivating a Salesforce Trigger

Introduction

Triggers are an Apex script that runs before or after data manipulation language(DML), as an example, it invokes when we insert, deletes, update, merge, undelete, upsert a record into the database.

Don’t forget to check out: Insert and Update multiple custom metadata records through Salesforce Apex.

For what reason do we Deactivate triggers?

At the point when we write triggers, we have to follow governor limits that are not writing SOQL queries or DML calls within the for loops and many more. But there are some scenarios in which it causes an error. There is the opportunity of a mass grouping of activities that might be brought forth when one activity happens. Code may work when there's just one record refreshed, however in the event that more than a great many records are changed in information tidy up practice then the code may not follow as far as possible from happening To work at this issue we may initially consider simply making them inactive.

These are some more reason to deactivate trigger:- 

  • Since at the one time, we can execute just one trigger so we need to deactivate another dynamic trigger.
  • At the indistinguishable time, several triggers are empowered then it makes inconveniences in execution.
  • A trigger should be eliminated before deployment in production if it is no longer wanted or is blocking off a deployment.
  • Triggers are not modified directly within a Production org, so it requires some of the steps using Developer tools to deactivate.

How we deactivate the trigger-  There are four ways to deactivate the trigger in Salesforce.

  • DEACTIVATE THE TRIGGER- Deactivate the sandbox trigger by techniques for unchecking the Active checkbox of a trigger. Make an outbound change set, transfer and send the changeset to the creation and afterward, the trigger underway will be actuated.
  • REMARK TRIGGER CODE- Comment entire apex trigger code in a sandbox and later use outbound changeset to pass on to the creation.

Example:-

trigger oppoTrigger on opportunity (before insert)
{
    /* your entire/whole code */ 
}
  • CUSTOM SETTINGS -With the utilization of the custom settings you can control whether a trigger will run or not. So for this, your custom settings will store the trigger name and its status is an idle checkbox.
trigger opportunityTrigger on Opportunity (before insert)
{
  Trigger_Set__c TrigSet = Trigger_Set__c.getValues(opportunityTrigger);
  if(TrigSet.is_Active__c == TRUE)
   {    
    //use your logic and write your code here 
   }
}
  • Utilizing ECLIPSE IDE-This is like the changeset approach however here you would make the trigger insert in the trigger's XML record and afterward send from overshadowing.

These are the accompanying advances:-

  1. First, you have to install Force.com IDE
  2. Utilizing IDE, associate with the Sandbox Example and search the trigger which you need to deactivate.
  3. Open the trigger's .xml document/record, and change the Status XML tag from Active to Inactive.
  4. Save the document/record/file.
  5. Pick the two documents/records (XML and Code) utilizing "Ctrl-click," and a while later right-click on one of them.
  6. Now, Select Force.com and Deploy/Convey to the server.
  7. Provide details for your Production organization and follow the subsequent stage.
  8. Class Deletion: To eradicate an Apex class, we have to change it to Deleted. Apex class Status changed to “ Deleted ” or “Active”  not “Inactive”.

Related Articles

Responses