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 ipicklist value for the Statu3__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
Correct Answer: A,C
A validation rule is a declarative way to enforce data quality and business logic on the records. A validation rule can prevent a record from being deleted if it does not meet certain criteria, such as having a specific field value. For example, a validation rule on the Container__c object could be:
NOT(ISPICKVAL(Status__c, "Decommissioned"))
This validation rule would prevent any Container record from being deleted unless its Status__c field is
"Decommissioned".
An Apex trigger is a programmatic way to execute custom logic before or after a record is inserted, updated, deleted, or undeleted. An Apex trigger can also prevent a record from being deleted by using the SObject.addError() method, which displays an error message and rolls back the transaction. For example, an Apex trigger on the Container__c object could be:
trigger ContainerTrigger on Container__c (before delete) { for (Container__c c : Trigger.old) { if (c.Status__c
!= 'Decommissioned') { c.addError('You can only delete decommissioned containers.'); } } } This trigger would iterate over the records that are being deleted and check their Status__c field. If the field is not "Decommissioned", it would add an error to the record and prevent the deletion.
B: After record-triggered flow and D. Before record-triggered flow are not correct answers because record-triggered flows cannot prevent records from being deleted. Record-triggered flows are a declarative way to automate business processes and execute actions when a record is created, updated, or deleted.
However, record-triggered flows do not have the ability to display custom error messages or roll back transactions. Therefore, they cannot be used to enforce the business requirement of only allowing decommissioned containers to be deleted. References: Validation Rules, Apex Triggers, Record-Triggered Flows
Recent Comments (The most recent comments are at the top.)
C and D are correct : https://help.salesforce.com/s/articleView?id=release-notes.rn_forcecom_flow_fbuilder_trigger_flow.htm&release=228&type=5
The correct answer is A & C.
D is incorrect as there's no option to choose a before with Delete trigger in Record-Triggered-Flow
• C. Apex trigger: An Apex trigger can be used to enforce complex business logic before or after a record is deleted. A before delete trigger can check the status of the Container__c record and prevent deletion if the status is not “Decommissioned”.
• D. Before record-triggered flow: A before delete flow can be configured to run logic before a record is deleted. The flow can be set up to check the Status__c field of the Container__c record and prevent the deletion if the status is not “Decommissioned”.