File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,35 @@ trigger MyTrigger on Account(after insert, after update) { // Noncompliant. The
2323----
2424
2525
26+ === Compliant solution
27+
28+ [source,apex]
29+ ----
30+ public with sharing class AccountTriggerHandler {
31+ public static void handleAfterEvents(List<Account> newAccounts, System.TriggerOperation triggerEvent) {
32+ switch on triggerEvent {
33+ when AFTER_INSERT {
34+ processNewAccounts(newAccounts);
35+ }
36+ when AFTER_UPDATE {
37+ // ...
38+ }
39+ }
40+ }
41+
42+ private static void processNewAccounts(List<Account> accountList) {
43+ for (Account a : accountList) {
44+ // ...
45+ }
46+ }
47+ }
48+
49+ trigger AccountTrigger on Account(after insert, after update) { // Compliant: The trigger just delegates the work
50+ AccountTriggerHandler.handleAfterEvents(Trigger.new, Trigger.operationType);
51+ }
52+ ----
53+
54+
2655== Resources
2756
2857* https://web.archive.org/web/20210509202306/https://github.com/ChrisAldridge/Lightweight-Trigger-Framework[Lightweight Apex Trigger Framework]
You can’t perform that action at this time.
0 commit comments