+ Start a Discussion
iswarya sekar 7iswarya sekar 7 

hello everyone !! I need to deactivate a trigger using custom setting without altering the trigger code. Can anyone help me in this? Thanks in Advance !!

trigger UpdateStage on Account (after insert, after update) {   // Performs Custom actions after Record gets saved.
   
    List<Id> accountId = new List<Id>(); // get the list of all Account's ID to be Updated.
    
    for(Account acc : Trigger.new)
    {
        if(acc.All_Opportunities_Won__c==True)   // Checks if the Condition is True. 
            accountId.add(acc.Id);
    }
    
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    
    for(Opportunity opp : [select id, StageName, Amount from Opportunity where AccountId in: accountId AND Amount != 0]) // used to get all records from above ID.
    {
        opp.StageName='Closed-Won';   //Update StageName in Opportunity
        oppsToUpdate.add(opp); 
    }
    
    update oppsToUpdate;   // Update all Opportunity in List.
}

 
Best Answer chosen by iswarya sekar 7
v varaprasadv varaprasad
Hi Iswarya,

Select check Unchecked to activate trigger again.

All Answers

v varaprasadv varaprasad
Hi Iswarya,

Please check once below sample code : 
trigger AccountTriggerHandler on Account (before insert,before update,after update) {
    Application__c bypassTrigger= Application__c.getInstance( UserInfo.getUserID() );
    if(!bypassTrigger.DisableValidations__c){
        if(trigger.isbefore && trigger.isinsert){
            for(account acc : trigger.new){
                if(acc.phone == null){
                    acc.phone.addError('phone no required');
                }
            }
        }
        
    }
    
} 
More info for creating custom settings and all please check once below link:
http://salesforceprasad.blogspot.sg/2017/01/how-to-disableenable-all-validation.html


I hope it helps you.

Please let me know in case of any other assistance.



Thanks
Varaprasad


 
iswarya sekar 7iswarya sekar 7
Without Altering the trigger code, can we deactive the trigger using custom setting?
Mukesh_SfdcDevMukesh_SfdcDev
Hi Iswarya,

You can not deactivate the trigger through custom setting but you can customize the trigger on the basis of custom setting value.
After creating the custom setting, you will need to modify your trigger to look up the custom setting value and skip all of your trigger logic if the value is set.

Thanks 
Mukesh Kumar
iswarya sekar 7iswarya sekar 7
Hi Mukesh,

For example, If we are create a checkbox field, when it is true it will activate the trigger, when false it will deactive it. Can this will happen using Custom Settings? i don't know. Just asking you some suggestions!! Help me!!
v varaprasadv varaprasad
Hi Iswarya,

No, it is not possible without using custom settings data in the trigger.


Thanks
Varaprasad
iswarya sekar 7iswarya sekar 7
Thank You VaraPrasad, i used custom setting data in my trigger. it deactivated the trigger. Now how i will again activate this?
trigger UpdateStage on Account (after insert, after update) {   // Performs Custom actions after Record gets saved.
    if(!Disabletriggers__c.getInstance().IsActive__c) {
        System.debug('Bypassing trigger due to custom setting');
        return;
    }
    List<Id> accountId = new List<Id>(); // get the list of all Account's ID to be Updated.
    
    for(Account acc : Trigger.new)
    {
        if(acc.All_Opportunities_Won__c==True)   // Checks if the Condition is True. 
            accountId.add(acc.Id);
    }
    
    List<Opportunity> oppsToUpdate = new List<Opportunity>();
    
    for(Opportunity opp : [select id, StageName, Amount from Opportunity where AccountId in: accountId AND Amount != 0]) // used to get all records from above ID.
    {
        opp.StageName='Closed-Won';   //Update StageName in Opportunity
        oppsToUpdate.add(opp); 
    }
    
    update oppsToUpdate;   // Update all Opportunity in List.
}
v varaprasadv varaprasad
Just make IsActive__c field true.
iswarya sekar 7iswarya sekar 7
hii, but this not working. i have to go to trigger and make it as checked.
User-added image
v varaprasadv varaprasad
You need to check it in custom settings, not on the trigger.
Make field to IsActive__c  false on custom settings.
iswarya sekar 7iswarya sekar 7
i have created a custom setting as Deactivate Trigger and a field as disable. when i run this, it deactivates the trigger. But now i dnt know how to activate it again.User-added image
v varaprasadv varaprasad
Hi Iswarya,

Select check Unchecked to activate trigger again.
This was selected as the best answer
iswarya sekar 7iswarya sekar 7
Hi VaraPrasad,
I Unchecked it. But the trigger is in inactive mode. Its not working for me.. What i did wrong?
mukesh guptamukesh gupta
Hi Iswarya,

Please follow :-
User-added image

please MARK AS BEST ANSWER!!!!

Regards
Mukesh