What happens after the code block executes? - ProProfs Discuss
Cancel
TopicsDown
Products Down
Follow Us:
FacebookTwitter
Advertisement

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(Case) childCases = new List (Case)(); 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: Sep 09, 2020

+ Answer
Request
Question menu
Vote up Vote down

5 Answers

Liquad (Qingjun) Li

Liquad (Qingjun) Li

Write something about yourself

Liquad (Qingjun) Li
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#!

upvote 1 downvote
Reply 

dprincloo

dprincloo

dprincloo
Dprincloo

Answered Jun 28, 2020

There should be some mechanism to check for parent.id==null so that child case won't create another child case.In above question the correct answer is The trigger enters an infinite loop and eventually fails.

upvote downvote
Reply 

michel.carvalho.lopes

michel.carvalho.lopes

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.
upvote downvote
Reply 

Varun Konda

Varun Konda

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

upvote downvote
Reply 

cmduquer

cmduquer

cmduquer
Cmduquer

Answered Sep 25, 2018

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

####
upvote downvote 1
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

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