Fetch Custom Setting Value in Apex

   
Requirement : Disable the Apex trigger using custom setting:

Solution : Create Custom setting:  SetUp>> Custom Setting >> New 

Create Custom setting and create a check Box field with name On_Off__c 


public class ClassName 
{
    public void onAfterUpdate(list<SOBJECT> triggerNew, map<id,SOBJECT> triggerNewMap, map<id,SOBJECT> triggerOldMap)
    {
// Write the Custom setting if On_Off__c = true then trigger method will be excute
List<CustomSetting__C>  cstriggerOnOff = CustomSetting__C.getall().values();
if(cstriggerOnOff != null && cstriggerOnOff .size()>0){
if(cstriggerOnOff [0].On_Off__c == true)
{
MethodName(triggerNew, triggerNewMap, triggerOldMap);
}
}
     
    }
    
    private void MethodName(list<SOBJECT> triggerNew,map<id,SOBJECT> triggerNewMap,map<id,SOBJECT> triggerOldMap)
    {   
        // Logic
    }
}



   Thanks
Sumit Shukla
    

Comments

Popular Post

Get Picklist Value Using Describe Call on VF Page

Get Max Value from Decimal List

What is Saml and Oauth and Authentication flow in salesforce