Section 3 · Process Automation and Logic · 28% of exam
3.4 Triggers, Transactions, Save Order, Limits, and Exceptions
Exam objective
Apply trigger and class best practices; explain governor limits, transaction boundaries, save-order interactions, recursion, cascading, and exception handling.
Structure trigger behavior for the event
Apex triggers run before or after record operations such as insert, update, delete, and undelete. Use context variables such as Trigger.new, Trigger.old, and their map forms to understand which records are being processed and how they changed. Before triggers can change fields on the records being saved without issuing DML on those same records. After triggers are useful when the record ID or saved-state information is needed for related work. The read-only nature of after-trigger records means a direct field assignment there is not a valid way to update the initiating records. Keep the trigger entry point short and delegate to a handler or service. This makes the event boundary visible and the business operation easier to test. Many teams use one trigger per object as an organizational convention, but the key exam concept is clear control of trigger behavior and bulk-safe logic. Gather IDs, query related records once, index them in maps, calculate changes, and perform collection DML. A trigger can receive batches, and integrations may cause repeated trigger invocations for a larger request.
Understand the transaction and governor model
A transaction groups operations that succeed or fail together. Governor limits apply according to transaction type and prevent one execution from monopolizing shared capacity. Moving work to Queueable, Batch, or another asynchronous mechanism creates different timing and transaction boundaries; it also changes how the user receives results and how failures are monitored. Do not pick asynchronous Apex simply because a synchronous design is inefficient. First correct repeated queries, excessive DML, nonselective scans, and unnecessary recursion.
A governor limit exception is generally not catchable. Use the current limits reference for exact values and identify which limit applies to the execution type. In Batch Apex, each execute chunk has its own transaction, so limits reset per chunk for applicable per-transaction governors. That does not remove daily or org-wide constraints, nor does it make a nonselective start query or inefficient batch harmless.
Trace save order and recursion
Saving a record invokes a defined sequence of platform actions: before-save processing, validation and other checks, before triggers, database save, after triggers, automation, and additional post-save work. The exact order includes more steps and has changed across releases; use Salesforce's current order-of-execution documentation for precise details. Workflow or Flow updates can re-enter parts of the save cycle. Thus one update may cause a trigger, one or more record-triggered flows, and a second update to the same record.
To analyze a scenario, list each automation that can update the record and the field it writes. Identify whether it runs before or after save, whether it checks a field transition or only a value, and whether a later write overwrites an earlier value. Recursion controls should express the business condition (for example, process only when a status transitions) rather than relying blindly on a static Boolean that may suppress valid work in bulk contexts.
Handle exceptions as part of the contract
Use try/catch when a method can recover, translate an error into a useful response, or handle a known partial failure. Catch the specific exception expected when possible. A custom exception can express a domain rule such as “the request cannot be approved without a related record.” Do not swallow errors or log sensitive information. If an exception remains unhandled, the transaction can roll back and the caller receives an error. Partial DML is a separate choice: inspect each SaveResult, retain successful outcomes only when the requirement permits it, and present actionable failures.
When a record has the wrong final value, identify the last automation that wrote that field. The sequence of writes often reveals the cause faster than inspecting every code line.
Extra concept: idempotency guards against duplicate effects
An operation is idempotent when repeating the same request does not create extra side effects. Stable external keys, transition-based entry criteria, and duplicate checks can help prevent duplicate follow-up records after retries. Idempotency complements transaction design; it does not excuse unbounded queries or missing error handling.
Key takeaways
- Triggers must handle collections, delegate logic, and use before/after contexts appropriately.
- Transaction limits, asynchronous boundaries, and the save order explain cascading automation and recursion.
- Handle expected errors clearly, distinguish partial DML from atomic rollback, and avoid fragile recursion flags. Official references:
- Salesforce Certified Platform Developer Exam Guide: https://help.salesforce.com/s/articleView?id=005298965&language=en_US&type=1
- Apex triggers: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-triggers.html
- Trigger best practices: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-triggers-bestpract.html
- Triggers and order of execution: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-triggers-order-of-execution.html
- Apex transactions and governor limits: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-limits-intro.html
- Apex exception statements: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-exception-statements.html
- Batch Apex: https://developer.salesforce.com/docs/platform/apex-dev/references/apex-dev/apex-batch-interface.html
