← Back to notes

Developers · Pattern

Apex Trigger Handler Pattern: Thin Triggers, Testable Logic

How I structure trigger logic to keep Apex bulk-safe, readable and easier to test.

Apex Trigger Handler Pattern: Thin Triggers, Testable Logic

The trigger should coordinate context and delegate behavior. Business logic belongs in handler or service classes, not inside the trigger body.

trigger AccountTrigger on Account (before insert, before update, after update) {
    AccountTriggerHandler.run(Trigger.operationType, Trigger.new, Trigger.oldMap);
}

This makes it easier to reason about bulk behavior, test specific paths and add new rules without turning the trigger into a long procedural script.