← Salesforce Platform Developer: Apex and Lightning
04 / 8 · 40 MIN

Triggers, limits, and asynchronous processing

Process collections and recover failures while respecting phases and transaction boundaries.

Concept and mechanism

Apex shares resources on a multitenant platform. Relevant limits belong to execution context; moving a query into a helper does not create a new allowance. Bulk design collects identifiers, queries sets, indexes results, and accumulates DML. Before context permits changing the triggering records before saving; in after context, those records are read-only. Choose phase by need without needlessly repeating a save. For effects tied to a transition, compare previous and new state. A global boolean preventing all later execution can omit legitimate work and does not replace a well-defined business condition or idempotent design.

Guided application

Separating asynchronous work also changes status communication and recovery. Enqueuing Queueable returns a monitoring identifier; it does not establish that indicators were calculated. Batch Apex executes chunks in separate transactions and does not guarantee the order required for implicit dependencies. Failure in one execute does not automatically undo completed chunks. Before retrying, reconcile effects and identify pending inputs. System.LimitException cannot be recovered through a normal catch: correct the consumption pattern and test representative volumes. This course analyzes these decisions conceptually; local checks do not execute Apex in a Salesforce org or demonstrate an actual instance’s limits.

IN PRACTICE

An import passes with one request and fails with 200 because it queries a rule on every iteration. Querying rules together and using collection DML addresses the cause. A new class containing the same loop would retain consumption.

Common pitfalls

Catch treated as limit recovery; after treated as writable context; job ID treated as success; Batch treated as one transaction; retries without effect reconciliation.

Related topics: Data model, identity, and metadata · Collections and choosing configuration or code · Queries, DML, and error outcomes

Take this idea with you

Design for collections, make transitions explicit, and track outcomes by transaction boundary. Asynchronous submission is not completion.

Create account

Reference: Bulk Apex Triggers · Platform Developer guide Summer 25