Maximum Trigger Depth Exceeded: This error occurs when a trigger causes recursive calls, leading to an infinite loop of execution. Solution: Use static variables in helper classes to prevent recursive trigger execution. Example: public class TriggerHelper { public static Boolean isTriggerExecuted = false; } trigger AccountTrigger on Account (after update) { if (!TriggerHelper.isTriggerExecuted) { TriggerHelper.isTriggerExecuted = true; // Trigger logic here } } Why Not Other Options? A: Permissions do not affect trigger recursion. B: Length of the trigger is unrelated to recursion. C: Code coverage does not influence runtime errors like recursion. References:Trigger Best Practices:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode /apex_triggers_best_practices.htm
最新のコメント (最新のコメントはトップにあります。)
正解は **D** です。
[cite_start]ドキュメントの「複数回実行の回避」セクション [cite: 1063-1074] に基づき解説します。
### 正解の解説
**D. トリガーが複数回実行されています。**
エラーメッセージ「maximum trigger depth exceeded(トリガーの最大深度を超えました)」は、**トリガーが再帰的に(繰り返し)実行され、システム制限(スタック深度16回)に達したこと**を示します。
**典型的な原因:**
* **無限ループ:** `after update` トリガーの中で、同じレコードを `update` すると、再び `after update` トリガーが呼び出され、これが無限に繰り返されます。
* **連鎖的な更新:** 取引先 (Account) のトリガーが取引先責任者 (Contact) を更新し、その Contact トリガーがまた Account を更新するようなケースです。
[cite_start]これに対処するには、`static Boolean` 変数を使用して、一度実行されたトリガーが同じトランザクション内で二度実行されないように制御(再帰制御)する必要があります [cite: 1068-1070]。
### 不正解の解説
**A. 開発者に適切なユーザー権限がありません。**
これは **不正解** です。権限不足の場合は「Insufficient Privileges」などのエラーが発生します。トリガーの再帰実行とは無関係です。
**B. トリガーが長すぎるため、ヘルパー クラスにリファクタリングする必要があります。**
[cite_start]これは **不正解** です。トリガー内のコード行数が多いこと自体は「最大深度超過」エラーの原因にはなりません(Apex文字数制限などはありますが、エラーメッセージが異なります)。ただし、ベストプラクティスとしてヘルパークラスへの分割は推奨されます [cite: 1004]。
**C. トリガーのコード カバレッジが十分ではありません。**
これは **不正解** です。カバレッジ不足は「デプロイ時」にエラーになりますが、実行時(テスト実行中)のロジックエラーである「最大深度超過」とは関係ありません。