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 posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page