Apexトリガは、営業担当者が商談を獲得するたびにOrder__cレコードを作成します。最近、このトリガによって2つの注文が作成されています。開発者がこれをトラブルシューティングするための最適な方法は何ですか?
正解:D
When a trigger unexpectedly executes twice (recursion), it is typically due to the Salesforce Order of Execution. A common cause is a workflow rule, process, or flow updating the same record that initiated the transaction, which re-triggers the original Apex trigger. To identify exactly where this second execution is being initiated, the most effective technique is to use system.debug() statements in conjunction with the Developer Console logs (Option D).
By placing debug statements at the start of the trigger (e.g., System.debug('Trigger Fired');), the developer can examine the execution log to see how many times that line appears. More importantly, the execution log provides a hierarchical "trace" of the entire transaction. The developer can look for entries like FLOW_CREATE_INTERVIEW or WF_RULE_EVAL_BEGIN between the two trigger execution blocks.
This trace reveals exactly which automation (Flow, Workflow, or another Trigger) caused the record to be updated a second time.
Option A is inefficient and disruptive to production environments. Option B is too broad and doesn't provide the internal execution context. Option C checks for code validity but does not diagnose runtime logic issues in a live environment. Tracing the execution through logs is the standard programmatic way to debug recursion and side effects in Salesforce.