質問

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

役に立ちましたか?

解決

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.

他のヒント

Read the following articles regarding trigger patterns and best practices

A Simple Trigger Template for Salesforce

Trigger Pattern for Tidy, Streamlined, Bulkified Triggers

Apex Triggers the Definitive Guide

Two interesting ways to architect Apex triggers

All articles provide a cool advice regarding architecture salesforce triggers and you can mix up these recommendations for create your own trigger template. I use the first one with some own improvements.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top