Created
April 5, 2018 08:46
-
-
Save meajinkya/90f3f94f65d59dd0f6e6eb5e62335332 to your computer and use it in GitHub Desktop.
A good approach for Apex triggers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A good approach to follow for trigger development | |
Any trigger's logic can be looked at in three parts(as below) and the code for that should also be written based on those parts: | |
1. Trigger event detection | |
This should go in the trigger where we write logic for trigger event detection and delegation to appropriate method in handler class. | |
2. Record filtering | |
Record filtering can be done using a separate class which can have different methods for filtering for each action. It may happen that a filter can be applied to two different actions, for which we can reuse the same method for filtering. | |
3. Actions (Business logic) | |
This should be typically done in a service class. The records filtered in step #2 can be passed on to the service class to perform actions like creating child records, updating parent record, etc on them. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment