hiexam
salesforce · Certified-Platform-Developer-II · Q604 · multiple_choice · topic_1

A developer writes the following Apex trigger so that when a Case is closed, a single Survey record is created for that…

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?
  • 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
Explanation
Answer is C. As the workflow field update, makes the trigger to run again, and in the same transaction instance, so trigger creates second record.

Reference: examtopics_top_comment

Practice with progress tracking

Sign in to track wrong answers, get spaced-repetition reminders, and run timed exam mode.