Apex Trigger (Option B): An Apex trigger can be written on theContainer__cobject to prevent deletion unless theStatus__cfield value is "Decommissioned". This allows custom logic to be executed during the deletion process. Apex Triggers Documentation Validation Rule (Option D): A validation rule is typically used to enforce conditions during record creation or update. However, it cannot directly restrict deletions. To ensure deletion restriction, an Apex trigger is more effective. Not Suitable: Option A(Before record-triggered flow): Flows triggered "before delete" are not available. Option C(After record-triggered flow): These occur after a record is deleted, so they cannot prevent the deletion process.
最新のコメント (最新のコメントはトップにあります。)
正:A、B
正:A、B
正解は **A** と **B** です。
(※選択肢Aの「欠陥」という言葉は、翻訳ミスである可能性が高いです。文脈から **「削除前のレコードトリガーフロー (Before-Delete Record-Triggered Flow)」** を指していると考えられます。)
### 領域の確認
* **領域:** **2. プロセスの自動化とロジック (Process Automation and Logic)**
* **トピック:** Apexトリガー、Flow Builder、レコード削除時の検証
-----
### 正解の解説
レコードが「削除」されるタイミングで、特定の条件(Status \!= '廃止')に基づいて処理をブロック(エラーにして停止)できるのは、以下の2つの機能です。
**B. Apexトリガー (Apex Trigger)**
これが最も伝統的で確実な方法です。
`before delete` トリガーを作成し、削除されようとしているレコード (`Trigger.old`) のステータスを確認します。もし条件を満たさない場合は `addError()` メソッドを使用することで、削除操作をキャンセルし、ユーザーにエラーメッセージを表示できます。
```apex
trigger ContainerTrigger on Container__c (before delete) {
for (Container__c c : Trigger.old) {
if (c.Status__c != 'Decommissioned') { // 廃止でなければ
c.addError('廃止されたコンテナのみ削除可能です。');
}
}
}
```
**A. レコードトリガーフロー(削除前) (Before-Delete Record-Triggered Flow)**
最近のSalesforceのアップデート(Flow Builderの機能強化)により、フローでもこれが可能になりました。
* **トリガー:** 「レコードが削除されたとき (A record is deleted)」
* **ロジック:** ステータスが「廃止」でないかを判定。
* **アクション:** **「カスタムエラー (Custom Error)」** 要素を使用して、処理をロールバックし、画面にエラーメッセージを表示します。
※ 選択肢の日本語「欠陥」は、おそらく英語の原文にあった "Flow" が何らかの理由で誤訳されたか、あるいは "Before Delete" の部分が誤って翻訳された可能性がありますが、消去法でもこれを選びます。
-----
### 不正解の解説
**D. 検証ルール (Validation Rule)**
これは **不正解** です。
ここが最大の引っ掛けポイントです。検証ルールは、レコードの **「作成 (Insert)」** および **「更新 (Update)」** 時にのみ評価されます。
レコードを **「削除 (Delete)」** す...
正:B、、、