Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Cleaner Salesforce Apex triggers have one clear entry point per object, delegate business logic to handler classes, process records in collections, account for shared transaction limits, and handle repeat execution and testing deliberately. These are practical design practices drawn from Salesforce developer guidance—not an official five-part Salesforce standard.

1. Use one trigger per object to make your own logic order explicit

Salesforce recommends consolidating an object’s trigger logic because independently defined triggers do not offer a dependable order of execution relative to one another. A single trigger can route the applicable event to the right handler, making the order of your application’s own logic visible and maintainable. See Salesforce’s Apex best-practices guidance and its developer checklist.

This controls only the order you establish within your trigger’s code. It does not dictate the order of every other Salesforce automation component in the transaction.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

2. Keep the trigger thin and delegate behavior

Treat the trigger as an entry point: identify the event and context, then hand off work to code organized for reuse and testing. Put business behavior in handler or helper classes rather than accumulating it in the trigger body. Salesforce’s Apex Recipes demonstrates a handler abstraction between the trigger declaration and the classes that contain logic.

A handler can make the path easier to inspect, but it is not automatically well-designed: its methods still need clear responsibilities, collection-based inputs where appropriate, and tests for the behavior they perform.

3. Bulkify the trigger and every layer it calls

An object trigger can receive up to 200 records in one invocation, as Salesforce Developers explains in its bulk-processing overview. Design for a collection from the start, not just for the single-record case.

  • Gather record IDs or other lookup values into sets.
  • Query related records using set-based conditions rather than querying once per triggering record.
  • Build changes or results in collections, then perform DML after the processing loop.
  • Pass collections into handler and helper methods and process them as collections there, too.

Moving a query that runs once per record into a helper method does not make it bulk-safe. Look for SOQL or DML inside loops throughout the full call path, including downstream work.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Choose contexts with order of execution and shared limits in mind

Use a before context when you can update fields on the triggering records before they are saved. Use an after context when the work needs the saved record state or involves related operations. The right context depends on what the logic needs to do; review the applicable Salesforce order-of-execution guidance alongside the trigger and any flows or other automation that participate in the transaction.

SOQL and DML budgets are shared transaction resources, not separate allowances for each trigger method. Consider the whole execution path rather than judging a handler in isolation. Salesforce’s Apex Governor Limits reference explains that limits are enforced at runtime and exceeding a limit causes an exception. The applicable limit values depend on execution context; consult the current documentation rather than relying on a number detached from that context.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. Plan for repeat execution and test meaningful paths

Identify what can cause the same transaction path to run again, including work performed by other automation. If recursion control or a bypass mechanism is justified, scope it to the operation that needs control. A static Boolean is not a universal solution: it can prevent legitimate work during bulk or multi-step transactions.

Tests should reflect how the implementation is used. Cover single-record and bulk paths, relevant trigger contexts, important downstream automation, and behavior that could approach transaction limits. Salesforce’s June 2026 trigger-consolidation article identifies missing bulk tests with 200 or more records as a review risk; that is a review signal, not a universal formal testing rule.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to review a trigger design

  • Is there one orchestration trigger for the object, with the intended order of the application’s own logic visible?
  • Does the trigger delegate business behavior instead of containing it all?
  • Can the trigger, handlers, and helpers process a collection without per-record queries or DML?
  • Have you considered the trigger’s context, other automation in the transaction, and cumulative resource use?
  • Are repeat execution, any bypass strategy, and the relevant bulk and context paths covered by tests?

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.