Add a public static Boolean hasRun = false; field to the trigger handler class
At the start of the relevant handler method, check if hasRun is true and return immediately if so
Set hasRun = true before executing any DML or logic that could re-fire the trigger
Reset the flag to false at the end of the method if you need subsequent trigger invocations in the same transaction (e.g., for a chained update) to execute
For fine-grained control, use a static Set<Id> of processed record IDs rather than a boolean so you can skip only already-processed records in a multi-batch scenario
Write a test that performs two sequential updates on the same record in one test method and asserts the logic runs exactly once or twice as intended
Known gotchas
Static variables persist for the duration of a single Apex transaction but reset between transactions, so the flag correctly gates recursion within one save but not across separate HTTP requests
Using a simple boolean flag prevents all re-execution, which breaks legitimate multi-step workflows where a trigger intentionally updates a record that should fire the trigger again on a different field
Test isolation: each test method runs in its own transaction context, so static flags reset between test methods but not within a single test method that issues multiple DML statements
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp