03 · The handler pattern

One method per event, a static bypass flag, and constructor-free classes your tests will thank you for.

Article 15m 1 min read Updated 14 Jul 2025
03 · The handler pattern
Modules

One method per event, a static bypass flag, and constructor-free classes your tests will thank you for.

The shape

beforeInsert(newList), afterUpdate(oldMap, newMap) — the trigger passes context variables straight through. The handler owns every decision; the trigger owns nothing.

The bypass flag

A public static Boolean lets data migrations and tests switch the handler off without touching metadata. Use sparingly; log every use.

Practice in your org

  • Open your Developer Edition org and follow along step by step
  • Change one thing at a time and note what happens
  • When something breaks, read the error before searching for it