0

I have a custom setting list called LPGCalculatorSettings__c that has a RollupTriggerSwitch that has a value of false. No how can I make it like a switch where in it will turn on/off my Trigger.

This is My trigger

trigger TotalOpportunityProductTrigger on OpportunityLineItem (after insert, after update, after delete) {

TotalOpportunityProductTriggerHandler tp = new TotalOpportunityProductTriggerHandler();

if(Trigger.isInsert && Trigger.isAfter){
tp.TotalField(Trigger.new);
}
else if (Trigger.isUpdate && Trigger.isAfter){
tp.TotalField(Trigger.new);
}
else if(Trigger.isDelete && Trigger.isAfter){
tp.TotalField(Trigger.old);
}


}
  • what is the name of this record and field name in custom setting ? – Ratan Paul Oct 24 '16 at 10:55
  • LPGCalculatorSettings__c is the name of the custom setting and within the value__c there is a RollupTriggerSwitch that has a value of false @Ratan – JMDF Oct 24 '16 at 12:35
  • JMDF.. check my answer and let me know if that make sense to you or not. – Ratan Paul Oct 24 '16 at 12:38
  • @Ratan Well actually it does not make any sense. Like how will I make it the custom trigger true, Things like that. Can you explain to me how this works. Thanks for the reply man. Really Appreciate it – JMDF Oct 24 '16 at 12:44
  • now this becomes confused. can you please clarify what you are looking for? in your question you are saying something else – Ratan Paul Oct 24 '16 at 12:46
1
trigger TotalOpportunityProductTrigger on OpportunityLineItem (after insert, after update, after delete) {

    // get the record from custom setting using getValues method and pass the name of record
    LPGCalculatorSettings__c  objCalSetting = LPGCalculatorSettings__c .getValues('RollupTriggerSwitch');

    //if your custo setting value is true then only execute trigger code
    if(objCalSetting.value__c == 'true'){
        TotalOpportunityProductTriggerHandler tp = new TotalOpportunityProductTriggerHandler();

        if(Trigger.isInsert && Trigger.isAfter){
            tp.TotalField(Trigger.new);
        }
        else if (Trigger.isUpdate && Trigger.isAfter){
            tp.TotalField(Trigger.new);
        }
        else if(Trigger.isDelete && Trigger.isAfter){
            tp.TotalField(Trigger.old);
        }
    }
}
| improve this answer | |
1

There is nothing that prevents you from doing something like this

List<LPGCalculatorSettings__c> myLPGCalcValues = LPGCalculatorSettings__c.getall().values();
TotalOpportunityProductTriggerHandler tp = new TotalOpportunityProductTriggerHandler();
     if(Trigger.isInsert && Trigger.isAfter){
          if(myLPGCalcValues[0].RollupTriggerSwitch == true){
              tp.TotalField(Trigger.new);
          }
      }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.