* A. Roll-up summary fields can cause the parent record to go through Save: * When a roll-up summary field on a parent object (like Account) is updated due to changes in child records (like Branch), the parent record (Account) is implicitly saved again. * This can result in the execution of the trigger on the parent object. Developers must consider this behavior to avoid unintended recursion or infinite loops. Reference:Roll-Up Summary Field Considerations C: The trigger may fire multiple times during a transaction: Triggers can execute multiple times within a single transaction, especially when there are operations such as updates to the parent record caused by roll-up summary fields or workflows. Developers should implement logic to ensure that the trigger handles multiple executions correctly (e.g., using a static variable to prevent recursion). Reference:Apex Trigger Best Practices Why not the other options? B: Duplicate rules are executed once all DML operations commit to the database: This is incorrect because duplicate rules executebeforethe DML operation is committed. Duplicate rules prevent duplicate records from being created or updated before the database operation occurs. Reference:Duplicate Rules Execution D: The validation rules will cause the trigger to fire again: This is incorrect because validation rules do not cause triggers to fire again. Validation rules validate the record and may prevent DML operations, but they do not independently re-trigger the Apex trigger. References: Trigger Context and Recursion Roll-Up Summary Field Documentation
最新のコメント (最新のコメントはトップにあります。)
GenerativeAI - 2025-11-19
正解は **A** と **C** です。
### 領域の確認 * **領域:** **2. プロセスの自動化とロジック (Process Automation and Logic)** * **トピック:** 実行順序 (Order of Execution)、トリガー、積み上げ集計項目
最新のコメント (最新のコメントはトップにあります。)
正解は **A** と **C** です。
### 領域の確認
* **領域:** **2. プロセスの自動化とロジック (Process Automation and Logic)**
* **トピック:** 実行順序 (Order of Execution)、トリガー、積み上げ集計項目
---
### 正解の解説
**A. ロールアップ サマリー フィールドにより、親レコードが保存されることがあります。**
これが **正解** です。
Master-Detail (主従) 関係において、Branch (子) レコードが作成・更新・削除されると、Account (親) にある「積み上げ集計項目 (Roll-up Summary Field)」の値が再計算されます。
Salesforceの内部動作として、この再計算は **「親レコードへの更新 (Update)」** として扱われます。
その結果、Account オブジェクトの **`update` トリガーが発火** します。開発者は、子レコードの操作によって意図せず親のトリガーが動いてしまう可能性を考慮しなければなりません。
**C. トリガーはトランザクション中に複数回起動される可能性があります。**
これも **正解** です。
1回の保存プロセス(トランザクション)の中で、トリガーは何度も呼び出されることがあります。
主な要因は以下の通りです。
1. **積み上げ集計項目の更新:** (上記Aの理由) 子の変更で親が更新され、親トリガーが動く。
2. **ワークフロールール/プロセスビルダーによる項目自動更新:** トリガーが一度終わった後に、ワークフローで項目が更新されると、**もう一度トリガー(Before/After)が再実行** されます。
開発者はこれ考慮し、**「再帰制御 (Recursion Control)」**(静的変数を使って2回目の実行を防ぐ処理など)を実装する必要があります。
---
### 不正解の解説
**B. すべての DML 操作がデータベースにコミットされると、重複ルールが実行されます。**
これは **不正解** です。
実行順序 (Order of Execution) の理解を問う問題です。
重複ルール (Duplicate Rules) は、**「データベースにコミットされる前 (After Triggers の後、コミットの前)」** に実行されます。
もしコミットされた後に実行されるとしたら、すでに重複データが保存されてしまっているため、保存を阻止することができません。
---
### 💡 学習のポイント:実行順序とトリガーの再実行
この問題は、**「Trigger が書かれた通りに 1回だけ動くとは限らない」** というSalesforce開発の落とし穴を指摘しています。
特に **「...