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 Answer 1

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
}
3
  • 2
    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, 2018 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. Nov 6, 2018 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, 2018 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .