0

We have a managed package and include some triggers.We have to give a option to stop a trigger in subscriber's org.

Could someone please suggest us the following option is good or not.

  • Create a custom setting as public visibility
  • creates boolean fields like isLeadtriggerstop,isaccounttriggerstop
  • In triggers,skip the code if the custom setting field is true.
  • Creates org default data in custom setting using Post Install script after install or upgrade the package

Sample code :

trigger TestLeads on Lead (after insert,before insert,before update) {

StopTriggers__c mc2 = StopTriggers__c.getOrgDefaults();

    if(mc2!=null && mc2.isLeadtriggerstop__c!=true){
    for (Lead ld : Trigger.new) {


        // my code

    }
}
}
1

I would do perform the opposite logic so you don't need a post install script.

StopTriggers__c mc2 = StopTriggers__c.getInstance();

if(mc2!=null && mc2.isLeadtriggerstop__c == true){

    return;
}

for (Lead ld : Trigger.new) {

     // my code
}
  • 1
    Hi, Dan! In order to properly format code, remember to use the {} button in the editor. I've gone ahead and taken care of it for you this time. – sfdcfox Nov 6 '18 at 13:47
  • Hi Dan,Thanks for the suggestions. getInstance() will return the current user custom setting data.Please noted we have planing to stop the trigger as org level not user level. We thought getOrgDefaults() is the best method. Please share your thoughts. – Madhu Nayaki Nov 6 '18 at 14:26
  • Hi, sorry for the delay in replying. getInstance does indeed return custom setting data set record for the current user. But the fields returned in the custom setting record are merged based on the lowest level fields that are defined in the hierarchy. So if no user/profile custom setting is defined it would use the org defaults. – Dan Beer Nov 7 '18 at 15:53

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.