A compact Salesforce Apex example that organizes trigger logic into handler and
service classes. The base TriggerHandler is adapted from Kevin O'Hara's
sfdc-trigger-framework.
It is a reference project for teams that want a single-trigger-per-object structure, explicit trigger-context methods, loop protection, and a small testable service layer. It is not a managed package or a drop-in replacement for an org's existing automation architecture.
- A
TriggerHandlerbase class that routes before/after trigger contexts to overridable methods. - Per-handler loop-count protection and a static bypass API.
- A
SampleTriggerHandlerandSampleServiceillustrating separation of orchestration from business logic. - Apex tests covering context dispatch, bypass behavior, and loop-count logic.
force-app/main/default/classes/ Handler, service, and tests
force-app/main/default/triggers/ Sample trigger entry point
-
Authorize a scratch org, sandbox, or development org with the Salesforce CLI.
-
Ensure the target org contains the sample schema used by this project:
Sample__cand itsSampleOwner__cfield. The schema is intentionally not included in this repository. -
Deploy the source:
sf project deploy start --source-dir force-app --target-org <org-alias>
-
Run the Apex tests:
sf apex run test --test-level RunLocalTests --target-org <org-alias> --wait 10
Create one trigger per object, instantiate the corresponding handler in that trigger, and override only the context methods needed by the object. Keep business operations in a service class so handlers remain focused on trigger orchestration.
No license is included. By default, the repository is not granted an open-source license; contact the author to request permission for reuse.