Apex & triggers

Synchronous and asynchronous Apex, governor limits, design patterns, best practices, trigger frameworks and testing, with production-quality code.

0%
10 concepts
12 questions

Start here: Apex & triggers

Plain-language orientation before the detail.

What this track covers

Apex is Salesforce's server-side programming language: strongly typed, Java-like, and running inside the platform's multitenant runtime. Architects aren't expected to write every line, but they are expected to decide when code is the right tool, how it's structured, and how it behaves at volume. That is what interviewers test.

This track covers:

  • Synchronous Apex: transactions, order of execution, governor limits.
  • Design and best practices: bulkification, security, error handling, layered design patterns.
  • Asynchronous Apex: future, Queueable (with Finalizers, AsyncOptions and cursors), Batch and Scheduled Apex, and when to use each.
  • Triggers and testing: trigger frameworks and tests that prove behaviour.

An analogy: a shared kitchen in a busy food hall

Food hallApex on Salesforce
Many restaurants share one kitchenMany customers (tenants) share the same platform
Each order gets a time slot, a set of burners and a fridge shelfEach transaction gets governor limits: CPU time, queries, DML, heap
A cook who fetches one ingredient per trip runs out of timeCode that queries inside loops runs out of limits: bulkify
Slow dishes are prepared in the back kitchen and delivered laterAsynchronous Apex moves heavy or slow work out of the user's transaction
House rules on who may use which knivesSecurity: sharing, object and field permissions, user mode
One head chef per station decides the order of workTrigger frameworks: one trigger per object, ordered handlers

If you remember one thing: everything in Apex is designed around the transaction and its limits.

Same idea, explained to four audiences

AudienceSay it like this
Business sponsor"We use code only where configuration can't do the job reliably. Where we do, it's structured so changes are safe and fast."
Admin"Flows handle the simple, changing rules. Apex handles complex logic, volume and integrations, and is exposed to Flow as actions you can reuse."
Developer"Bulk-safe services behind thin entry points, one trigger per object, user-mode data access, async for callouts and volume, and tests that assert behaviour."
CTA review board"Code is a liability we accept deliberately. The design bounds it with layering, a trigger framework, async patterns with error recovery, and governance for performance and security."

When code is the right tool (and when it isn't)

Choose Apex when logic is complex or spans many objects; volume or performance matters; you need callouts with retries; you need precise unit tests; or the same operation is called from many entry points (Flow, LWC, APIs, batch).

Prefer configuration when the rule is simple and changes often, admins own it, and a before-save flow or validation rule can do it.

How to study this track

  1. Learn the order of execution and the limits table until you can draw and recite them.
  2. Practise the set-and-map pattern until it's automatic.
  3. Be able to compare future, Queueable, Batch, Scheduled and Cursors in one table.
  4. Prepare your trigger framework description and one async integration story with retries.

Misconceptions interviewers like to test

  • "with sharing makes the code secure." It enforces record sharing only. Object and field permissions need user mode or stripInaccessible.
  • "Future methods are the fastest async option." All async work is queued; Queueable gives more control and is recommended for new code.
  • "75% coverage means the code is tested." Coverage measures lines run, not behaviour proven.

Concept map

How the building blocks fit together. Select a concept to open it.

Concepts

Grouped by theme.

Asynchronous Apex

Interview prep · 12 questions

Scenario · 3Conceptual · 4Design · 2Trade-off · 2CTA board · 1★ 5 must-prepare