Question 1
IntermediateProcess Automation and Logic · Apex Triggers vs. Declarative Automation
A financial services company has a requirement to prevent the deletion of any Opportunity record with a 'Closed Won' status by any user except those with a 'System Administrator' profile. A junior developer suggests creating a validation rule. As the senior developer, what is the most robust and secure approach to meet this requirement?
Answer and explanation
Correct answer: B
The most robust solution is an Apex trigger on the 'before delete' event. Validation rules do not fire on delete operations, so they cannot be used to prevent record deletion. A 'before delete' trigger can inspect the records being deleted, check the user's profile, and use the .addError() method on the records that should not be deleted, effectively blocking the DML operation. This approach is secure and directly addresses the requirement which cannot be met by declarative tools.
