Salesforce Certified Platform Developer II — Question 31
A developer writes the following Apex trigger so that when a Case is closed, a single Survey record is created for that Case. The issue is that multiple Survey_c records are being created per Case. trigger CaseTrigger on Case (after insert, after update){ List<Survey_c> createSurveys = new List<Survey_c>(); for (Case c : trigger.new){ if (c.IsClosed && (trigger.isInsert II trigger.isUpdate && trigger.oldMap.get(c.Id).IsClosed == false)){ createSurveys.add(new Survey_c(Case_c = c.Id)); } } insert createSurveys; }
What could be the cause of this issue?
Answer options
- A. A user is creating the record as Closed
- B. A workflow rule is firing with a Create Task action
- C. A workflow rule is firing with a Field Update action
- D. A user is editing the record multiple times
Correct answer: D
Explanation
The correct answer is D because if a user edits a Case multiple times while it is open and then closes it, the trigger will execute for each edit, leading to multiple Survey_c records being created. Options A, B, and C do not directly relate to the trigger's logic that results in multiple records being generated; they involve different scenarios that do not explain the duplication issue.