ApexSensei

All drills

Triggers: Apex practice drills

Before and after triggers, handler classes, bulk patterns, recursion guards and roll-ups.

Intermediate · Check and Run with Apex Path ($19 a month).

  1. Write your first before-insert trigger Beginner · 10 min

    A before insert trigger sees new records in Trigger.new before Salesforce saves them.

  2. Create follow-up Tasks after Contact insert Intermediate · 15 min

    Use after insert when related records need the new records' Ids.

  3. React to a Contact email change Intermediate · 15 min

    An update trigger sees the new record in Trigger.new and the saved one in Trigger.oldMap, keyed by Id.

  4. Route Case trigger contexts Intermediate · 15 min

    One trigger can handle several events.

  5. Mark parent Accounts in bulk Intermediate · 18 min

    A bulk-safe trigger handler collects parent Ids first and runs one query and one update for the whole batch.

  6. Move Opportunity logic to a handler Intermediate · 15 min

    A trigger should pick the event; a handler class should do the work.

  7. Require a Contact email domain Intermediate · 18 min

    A before-trigger handler can reject a single record with a field-level addError.

  8. Stop recursive Account updates Advanced · 20 min

    A static variable keeps its value for the whole transaction, so a static Set<Id> can remember which records a trigger already handled.

  9. Block deleting Accounts with open deals Advanced · 20 min

    A delete trigger has no Trigger.new; the records are in Trigger.old and keyed by Id in Trigger.oldMap.

  10. Keep a Contact count on Account Advanced · 25 min

    A rollup counts child rows on a parent by running one aggregate query, not by adding or subtracting 1 per event.

  11. Create a child record only when a field changes Intermediate · 18 min

    In an after update trigger, compare the new value to the old value from Trigger.oldMap before you create a child record.

Start practicing free