A Salesforce developer bulk-safe trigger checklist should verify collection-based processing, bounded database work, realistic bulk tests, and explicit failure handling. Review the complete save path, including helper classes and related automation. Before deployment, prove that mixed records produce the right outcomes together, without duplicate side effects or work that grows unnecessarily with batch size.
Define the trigger contract before writing the handler
Start with a short contract for the object and operation. Identify the business condition, the fields that establish it, and the records the trigger may change. Separate a new record becoming eligible from an existing record staying eligible. That distinction gives the reviewer something more precise to approve than “run when saved.”
For a proposed opportunity follow-up rule, specify what should happen when the qualifying condition changes, when unrelated fields change, and when a follow-up already exists. Treat this as a design example: the actual fields and eligibility rule belong in the team’s acceptance criteria.
- List the supported insert, update, and other operations explicitly.
- Identify dependencies on parent records, related records, and existing automation.
- Define expected outcomes for missing relationships and rejected input.
- Assign ownership of fields that several automation paths can change.
Review the business transition with the people responsible for Salesforce sales workflow design. A trigger can process a collection efficiently while implementing the wrong transition.
Review the Salesforce developer bulk-safe trigger checklist
Walk through the entry point and follow its calls into the handler, selectors, and shared utilities. Apex triggers can receive collections of records. Code that takes the first record as representative of the collection leaves other records unprocessed. A helper called repeatedly with one record can also conceal repeated database work.
- Collect candidates. Evaluate records individually and gather those that meet the business condition. For updates, plan the comparison between previous and proposed values.
- Collect relationship keys. Use a set to collect distinct identifiers needed for related data. Decide what a missing identifier means before building the query.
- Retrieve related data together. Shape queries around the candidate identifiers and the fields the calculation needs.
- Index results. Use maps to associate retrieved records with their identifiers. Handle a key without a matching result deliberately.
- Calculate changes. Build the proposed changes in memory and consolidate repeated changes to the same target.
- Save collections. Gather required writes into collections rather than issuing a database operation for each input record.
Check loops inside helper methods as closely as loops in the trigger. Moving a query into another class does not remove its repeated execution. Ask the reviewer to trace one candidate and then explain how the same path behaves for a collection containing different candidates.
Bound related-record work and repeated effects
Removing database statements from loops addresses one failure pattern. The amount of retrieved data and the calculation performed on it still need review. A small group of parent records may have many children. Avoid retrieving a broad related dataset and then discarding nearly all of it in memory.
Estimate work along two dimensions: the number of incoming records and the number of related records per incoming record. Include a test case with concentrated relationships, such as many candidates sharing one parent, and another with candidates spread across different parents. These shapes expose different assumptions in grouping and aggregation.
Trace paths that write back to the initiating object or to an object that can cause another save. Define the intended repeated-save outcome. A field value may already be correct, or a related action may already exist. Prefer an eligibility rule that makes that condition visible, and test it rather than assuming a guard will protect the transaction.
Review any proposed recursion guard against separate eligible groups processed during the same operation. Ask whether it could suppress work that has not happened yet. Document the guard’s scope and the test that demonstrates the intended behavior.
Where trigger changes cross system boundaries, align ownership and replay expectations with Salesforce integration architecture. Record which component decides whether an external side effect has already occurred.
Build test data that exposes collection mistakes
Create test records with deliberate variation. A collection of identical records may exercise the bulk path while hiding assumptions about eligibility, relationships, and ordering. Keep expected outcomes alongside the fixture design so that someone reviewing the test can understand why each group exists.
- Single candidate: establishes a readable baseline for the business rule.
- Mixed eligibility: combines qualifying and nonqualifying records in one operation.
- Shared relationships: places several candidates under the same parent to exercise consolidation.
- Distinct relationships: separates candidates so that the test can detect values leaking between groups.
- Missing related data: checks the agreed skip, default, or rejection behavior.
- Changed and unchanged fields: distinguishes a qualifying transition from an unrelated edit.
- Existing output: checks the expected result when a related action already exists.
Use a bulk operation to submit the collection in the test. Repeating a single-record save in a loop does not demonstrate the same collection path. Include a larger scenario that exercises repeated trigger invocations, alongside smaller tests that make individual business failures easy to diagnose.
Create the test data the scenario needs instead of relying on incidental business records in the organization. For an import-related trigger, agree representative relationship and data-quality cases with the team handling Salesforce data quality and migration. Keep the fixtures synthetic and easy to rebuild.
Assert outcomes, failures, and resource use
A test that completes without an exception leaves the business result unproven. Requery affected records and assert their values, relationships, and counts. Check records that should remain untouched as well as records that should change. For grouped work, verify the association between each input group and its output.
Separate test setup from the operation under test with Test.startTest() and Test.stopTest(). This gives the tested operation a fresh set of governor limits rather than mixing its consumption with fixture creation. Inspect resource use around the relevant path and compare small and larger scenarios for unexpected growth.
Define failure expectations before choosing the database operation. If a scenario permits partial success, inspect the result associated with each submitted record and verify both accepted and rejected outcomes. If the business operation should fail together, assert that outcome and check for unintended persisted changes.
Use readable assertion messages that identify the business condition. A failed comparison should help the next developer locate a missing transition, duplicate action, or incorrect parent association. Passing coverage numbers do not establish those results.
Use a deployment review with named evidence
Bring the trigger contract, test matrix, and test results to review. Ask the reviewer to challenge a concrete batch shape: mixed eligibility, shared parents, substantial child data, and a repeated save. Resolve unanswered behavior before treating the change as ready.
For help planning this work, see Salesforce implementation.
- Which query or write could execute once per candidate through a helper?
- Which assumption depends on input order or a shared mutable value?
- Which test proves that ineligible records remain unchanged?
- What happens when the same business event is submitted again?
- Who will inspect failures after release, and what evidence will they use?
- What recovery action restores the business outcome if the new rule is disabled?
Validate against the target organization’s automation and release configuration. Record the tested code revision, relevant configuration dependencies, deployment owner, and recovery decision. After deployment, use an agreed verification sample and compare actual outcomes with the contract, including records that should have been skipped.
Questions about trigger review handoffs
Who should approve a change to the trigger’s business rule?
Ask the process owner to approve eligibility and expected outcomes, and a technical reviewer to approve the implementation. Keep those decisions together so a later maintainer can distinguish a deliberate exception from a coding defect.
How should a team record an accepted performance tradeoff?
Describe the workload assumption, the reason for the tradeoff, and the condition that would trigger another review. Give the decision an owner. A comment saying “optimized” does not explain which constraint was accepted.
What should a support handoff include?
Provide the affected business operation, symptoms of failure, information needed to investigate, and the escalation owner. Explain how support can identify the relevant records without exposing sensitive field values in a general incident channel.
When should an older trigger return to review?
Revisit it when a new import, integration, relationship pattern, or business rule changes the workload assumptions. Treat those events as prompts to rerun the relevant scenarios and update the acceptance evidence before expanding usage.
Pages in this section
More in this section
- Salesforce Automation & Workflows
- Flow or Apex for Record-Triggered Automation: Choosing by Logic Density
- Starting With the Simplest Orchestration and Adding Agent Steps Only When Needed
- One Automation Entry Point per Object: Avoiding Competing Flows and Triggers
- Auditability Rules for Agent Actions That Cannot Be Reversed