CRT-450 practice question 28 of 30

Managers at Universal Containers want to ensure that only decommissioned containers are able to be deleted in the system. To meet the business…

Full set: 201 questions
Managers at Universal Containers want to ensure that only decommissioned containers are able to be deleted in the system. To meet the business requirement a Salesforce developer adds "Decommissioned" as a picklist value for the Status _c custom field within the Container _c object. Which two approaches could a developer use to enforce only Container records with a status of "Decommissioned" can be deleted? Choose 2 answers
Answer options
A: Before record-triggered flaw Correct answer
B: Apex trigger Correct answer
C: After record-triggered flow
D: Validation rule
Correct Answer:
A. Before record-triggered flaw; B. Apex trigger
Explanation

To prevent a record from being deleted based on its field values, the logic must execute before the deletion is committed to the database. An Apex trigger in the before delete context is a standard programmatic solution. It can inspect the Statusc field of the records in Trigger.old and use the addError() method to prevent the deletion if the status is not "Decommissioned". A Before record-triggered flow that runs when a record is deleted serves as the declarative equivalent. This flow can evaluate the record's status and use a Custom Error element to halt the transaction and display an error message, effectively enforcing the business rule without code.

References

1. Apex Developer Guide - Triggers: "There are two types of triggers: Before triggers are used to update or validate record values before they’re saved to the database. After triggers are used to access field values that are set by the system (such as a record's Id or LastModifiedDate field), and to affect changes in other records." The addError() method, used to prevent DML operations, is used in before triggers. (See "Trigger Context Variables" and "Validation with Triggers").

2. Salesforce Flow Documentation - Record-Triggered Flow: "A record-triggered flow starts when a record is created, updated, or deleted." For deletion, the flow runs before the record is deleted, allowing for validation. The Custom Error element can be used to "block a save in a record-triggered flow." This applies to the before-delete context.

3. Salesforce Documentation - Triggers and Order of Execution: The order of execution clearly states that before delete triggers run before the record is deleted from the database, while after delete triggers run after. Preventing the operation must happen in the before context.

4. Salesforce Help - Validation Rules: "Validation rules verify that the data a user enters in a record meets the standards you specify before the user can save the record." This documentation confirms their scope is limited to insert and update operations, not deletes.

Scroll to Top