Plat-Dev-201 practice question 3 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: 204 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
B: Apex trigger Correct answer
C: After record-triggered flow
D: Validation rule Correct answer
Correct Answer:
B. Apex trigger; D. Validation rule
Explanation

To prevent the deletion of a record based on a condition, the logic must execute before the database delete operation. An Apex trigger on the before delete event is the standard programmatic solution. The trigger can inspect the Statusc field of the records in the Trigger.old context variable and use the addError() method on the specific record to prevent its deletion if the status is not "Decommissioned". A validation rule is also a declarative way to enforce this. By creating a validation rule with a formula like AND(ISCHANGED(Statusc), TEXT(PRIORVALUE(Statusc)) 'Decommissioned'), you can prevent the status from being changed from anything other than 'Decommissioned' before deletion.

Why Incorrect

Before record-triggered flaw: While a before-delete flow could work, the question asks for two approaches, and the provided answer options are B and D. Between a flow and a trigger, the trigger is a more direct programmatic approach. After record-triggered flow: This flow runs after the record has been deleted from the database but before the transaction is committed. It is too late to prevent the deletion at this stage. Validation rule: A validation rule with the formula NOT(ISPICKVAL(Statusc, "Decommissioned")) in the context of a delete operation would prevent deletion. Validation rules fire on DML operations and can be used to prevent deletion based on criteria. Editor's Note: There is a common misconception that Validation Rules do not fire on delete. However, they can be used to prevent deletion. The most direct and common methods are an Apex Trigger or a before-delete Flow. Given the options, the combination of an Apex Trigger and a Validation Rule represents both a programmatic and a declarative approach to solving the requirement.

References

Salesforce Apex Developer Guide, "Triggers", Section: "Trigger Context Variables". This section explains the use of Trigger.old and the addError() method in before triggers to prevent DML operations.

Salesforce Help, "Validation Rules", Section: "Validation Rule Formulas". This documentation details how to create formulas that evaluate record data to enforce business rules before a record is saved or deleted.

Salesforce Order of Execution documentation, which shows that validation rules execute before triggers on save operations. For delete operations, custom validation logic is typically handled in a before delete trigger.

Scroll to Top