Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion rules/S5384/apex/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,34 @@ This rule raises an issue when a Trigger function contains one of the following

[source,apex]
----
trigger MyTrigger on Account(after insert, after update) { // Noncompliant. The trigger is processing records itself instead of using a Trigger Handler.
trigger MyTrigger on Account(after insert) { // Noncompliant. The trigger is processing records itself instead of using a Trigger Handler.
for(Account a : Trigger.New) {
// ...
}
}
----


=== Compliant solution

[source,apex]
----
// In your .cls file
public with sharing class AccountTriggerHandler {
public static void handleAfterEvents(List<Account> newAccounts) {
for(Account a : newAccounts) {
// ...
}
}
}

// In your .trigger file
trigger AccountTrigger on Account(after insert) { // Compliant: The trigger just delegates the work
AccountTriggerHandler.handleAfterEvents(Trigger.New);
}
----


== Resources

* https://web.archive.org/web/20210509202306/https://github.com/ChrisAldridge/Lightweight-Trigger-Framework[Lightweight Apex Trigger Framework]
Expand Down
Loading