Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce Apex Trigger Framework Sample

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.

Included patterns

  • A TriggerHandler base class that routes before/after trigger contexts to overridable methods.
  • Per-handler loop-count protection and a static bypass API.
  • A SampleTriggerHandler and SampleService illustrating separation of orchestration from business logic.
  • Apex tests covering context dispatch, bypass behavior, and loop-count logic.

Project structure

force-app/main/default/classes/    Handler, service, and tests
force-app/main/default/triggers/   Sample trigger entry point

Deploying the sample

  1. Authorize a scratch org, sandbox, or development org with the Salesforce CLI.

  2. Ensure the target org contains the sample schema used by this project: Sample__c and its SampleOwner__c field. The schema is intentionally not included in this repository.

  3. Deploy the source:

    sf project deploy start --source-dir force-app --target-org <org-alias>
  4. Run the Apex tests:

    sf apex run test --test-level RunLocalTests --target-org <org-alias> --wait 10

Adapting it

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.

License

No license is included. By default, the repository is not granted an open-source license; contact the author to request permission for reuse.

About

Apex trigger-handler framework sample with context routing, loop protection, and tests.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages