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 questionsTo 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.
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.
Keep practicing
Take the free CRT-450 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CRT-450 practice questions
- Question 2A developer created a child Lightning web component nested inside a parent Lightning web …
- Question 4A developer needs to make a custom Lightning Web Component available in the Salesforce Cl…
- Question 6Given the following Apex statement: Account myAccount = [SELECT Id, Name FROM Account); W…
- Question 8Which action causes a before trigger to fire by default for Accounts?
- Question 9Universal Containers (UC) wants to lower its shipping cost while making the shipping proc…
- Question 10A custom picklist field, Pool Preference ¢, exists on a custom object. The picklist conta…
