What happens after the code block executes? A developer has the - ProProfs Discuss
Topics
Products
Follow Us:

What happens after the code block executes? A developer has the following trigger that fires after insert and creates a child Case whenever a new Case is created. List childCases = new List(); for (Case parent : Trigger.new) {Case child = new Case (ParentId = parent.ID, Subject = parent.Subject); childCases.add(child);} insert childCases;

This question is part of Salesforce Platform Developer 1
Asked by Cmduquer, Last updated: Jan 18, 2020

+ Answer
Request

4 Answers

Liquad (Qingjun) Li

Write something about yourself

Liquad (Qingjun) Li, Software Engineer, Enter your education, Shanghai, China

Answered Oct 17, 2018

C.

The Recursive fails when it exceeds 16 times that is limitation of trigger rescursive invocation.

Total stack depth is 16 for any Apex invocation that recursively fires triggers due to insert, update, or delete statements.

https://developer.salesforce.com/docs/atlas.en-us.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apexgov.htm#!

1
 

michel.carvalho.lopes

Michel.carvalho.lopes

Answered Sep 29, 2019

This answer is definitely wrong because the child cases created by this trigger will fire again the same trigger that will create new child cases, which in turn will trigger the trigger again, thus generating the looping.

So the correct answer would be:

  • The trigger enters an infinite loop and eventually fails.
 

Varun Konda

Varun Konda

Answered May 07, 2019

To Avoid infinite loop, you have to check parent.id == null so a child case won't create another child case

 

cmduquer

Cmduquer

Answered Sep 25, 2018

Child case is created for each parent case in Trigger.new.

####
1
 

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.