A developer needs to prevent the creation of Request__c records when certain conditions exist in the system. A RequestLogic class exists that checks the conditions.
What is the correct implementation?
A.
apex
CopyEdit
trigger RequestTrigger on Request__c (before insert) {
RequestLogic.validateRecords(Trigger.new);
}
B.
apex
CopyEdit
trigger RequestTrigger on Request__c (before insert) {
RequestLogic.validateRecords(trigger.new);
}
C.
apex
CopyEdit
trigger RequestTrigger on Request__c (before insert) {
if (RequestLogic.isValid(Request__c)) {
Request.addError('Your request cannot be created at this time.');
}
}
D.
apex
CopyEdit
trigger RequestTrigger on Request__c (after insert) {
if (RequestLogic.isValid(Request__c)) {
Request.addError('Your request cannot be created at this time.');
Comprehensive and Detailed Explanation From Exact Extract:
When preventing the creation of records using business logic in an Apex trigger, it’s crucial to do it in a before insert trigger context so the records are not committed to the database. The method should be called using trigger.new (case-sensitive) which references the list of new records being inserted.
[Reference:, Triggers and Order of Execution, Apex Trigger Context Variables, , , ]
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit