Activity › Forums › Salesforce® Discussions › In Salesforce,How to pass the context variables in handler in triggers ?
-
In Salesforce,How to pass the context variables in handler in triggers ?
Posted by Kirandeep on February 19, 2020 at 5:14 PMIn Salesforce,How to pass the context variables in handler in triggers ?
Ratnesh replied 6 years, 3 months ago 3 Members · 2 Replies -
2 Replies
-
It is always a best practice to write a single trigger on object and process all operation in apex class (we called it as handler) instead of
writing logic in trigger. In handler you can specify the order of event based on different context variables. If you write many triggers in on object,
then you cannot control the order in which triggers gets executed.For best practice, use below suggestion:
1. Pass all trigger context variables to static method (say “OperationManager”)in handler class.
2. Create different static methods for different operations which you need to perform.
3. Control the order of different operation in “OperationManager” static method based on context variables.
4. Also you can create different apex classes and call them from “OperationManager” static method. - [adinserter block='9']
-
Fundamentally, to contrast old field estimation of record and the new incentive in trigger we have to get to trigger.oldmap and trigger.newmap. Salesforce gives trigger.oldmap wherein all the old records are put away in map with keyset as their id’s. We can contrast the old qualities and new qualities as in the beneath model. Let’s see how we can actualize such information approval by getting old incentives in triggers.
Log In to reply.