function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The new LearnerThe new Learner 

How to stop the triggers not to fire for any profile using custom setting

Hi Experts,

Can anyone help me how out, how to the stop the triggers not to fire any profile using custom setting. Thanks in advance
Meghna Vijay 7Meghna Vijay 7
Hi,

You can create hierarchy custom setting and create "isProfile" checkbox custom field and set it's value as false and then use that check in your apex trigger before caling any method to perform certain actions.

Thanks
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Make use of custom setting using which you can control whether a trigger should run or not.  Create a custom setting (say Trigger_Settings__c).  Add a checkbox field “Is Active”.  So your custom settings will store the trigger name and its status in IsActive checkbox.

Then in your 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 oppTrigger on opportunity (before insert){
  Trigger_Settings__c TS = Trigger_Settings__c.getValues('oppTrigger');
  if(TS.is_Active__c == TRUE){
    //your trigger code
  }
}

So, every time you want to turn off the trigger in production, just go to your custom settings and uncheck the IsActive checkbox for that trigger.

Please refer to the below links which might help you further with the above requirement.

https://riptutorial.com/salesforce/example/17388/using-hierarchy-custom-settings-to-disable-apex-code

https://jkilburn2043.wordpress.com/2015/10/06/turn-triggers-on-and-off-with-custom-settings/

https://salesforce.stackexchange.com/questions/166252/activate-and-deactivate-trigger-using-custom-setting

https://sfdcfanboy.com/2017/11/23/a-tip-a-day-23-5-ways-to-stop-trigger-in-production/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
The new LearnerThe new Learner
Hi Khan/Meghna,

I have created custom setting like below, how can i get to know that whether this code working for all the profiles or not and also for specific user as well. Kindly help me.

Application__c bypassTrigger= Application__c.getInstance( UserInfo.getProfileId() );
if(!bypassTrigger.DisableTrigger__c){
 
Raj VakatiRaj Vakati
You can do some think differently instead of using the custom settings or metadata ..   ( Offcourse you have its own reason to use custom setting or metadata ..

Create a Checkbox field on the User Bypass_Trigger__c
if you set this value to true you can bypass the trigger like below 
 
trigger Demo on Account (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
    User logUser=[Select id,Bypass_Trigger__c 
                       from User
                       where id=:UserInfo.getUserId()] ;
    if(!logUser.Bypass_Trigger__c){

		//Your Logic here 
    }
}

 
Meghna Vijay 7Meghna Vijay 7
Hi @the new learner,
Application__c bypassTrigger= Application__c.getInstance( UserInfo.getProfileId() );
if(!bypassTrigger.DisableTrigger__c){
   System.debug('Trigger is firing');
}
You can login with different users having different profiles and identify if the trigger is firing or not by adding System.debug('Trigger is firing') in your code.

Thanks