APEX-Q03โ˜… Must-prepareConceptual IntermediateApex & triggers#apex#design-patterns#triggers

Describe your trigger framework.

Your confidence:Not rated

Model answer

I follow five rules and use a small shared framework (or an established open-source one such as the Trigger Actions Framework):

  1. One trigger per object for all events; multiple triggers on one object have no guaranteed order.
  2. No logic in the trigger. It calls a dispatcher that routes to handler methods per event (beforeInsert, afterUpdateโ€ฆ).
  3. Handlers are thin and bulk-safe. They filter the records that actually changed (compare Trigger.oldMap) and call service classes.
  4. Bypass switches from custom metadata, custom settings or a custom permission, so data loads and integrations can skip specific automation without a deployment. Bypasses are logged.
  5. Recursion control by record ID and event, so the same records aren't processed twice for the same event, while legitimate re-entry still works.

Flow coexistence: either agree ownership per object (simple before-save field updates in Flow, complex logic in Apex), or use a metadata-driven framework where Flow and Apex actions are registered with an explicit order.

Testing: each handler has bulk tests, and the bypass and recursion logic have their own tests.

โœ” Key points to hit

โœ– Red-flag answers

  • Logic directly in the trigger body
  • Several triggers on one object
  • A single static boolean for recursion
  • No way to bypass for data loads

โ†ช Follow-ups

How do you bypass automation for a data migration user?

Assign a custom permission (or set a custom metadata/custom setting flag) that the framework checks before running handlers. Scope it to the specific handlers, log its use and remove it after the migration.

How do you order Apex and Flow on the same object?

Use a metadata-driven framework that registers both with an order number, or agree that before-save flows handle only same-record field defaults while Apex handlers own everything else.