Search code examples
salesforceapex-code

Can I call a method in a trigger from another trigger in salesforce?


Can I call a method in a trigger from another trigger in salesforce? If so, can I just use inheritance?


Solution

  • It is a best practice to take all your trigger logic into a sepparate class. For example your tigger could looks like this

    trigger AccountBeforeUpdate on Account (before update) {
        TR_AccountBeforeUpdate.doSomeActions(trigger.new, trigger.oldMap);
    }
    

    And in TR_AccountBeforeUpdate you put all your logic. You can leave some data agregation in the trigger itself and pass you own set maps or lists (containing only objects matching some examples) Now you can call methods from TR_AccountBeforeUpdate or even instantiate it.