function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rob Koch 1Rob Koch 1 

Developer script exception System.LimitException: Maximum stack depth reached: 1001. Is this recursion error a result of and endless loop that returns no records??

Andrew GAndrew G
More likely it is a loop that continually calls itself without an escape option.

For example , an onInsert Trigger on a Contact that creates and inserts another Contact record, which on insert, calls the code which inserts another contact which invokes the insert trigger to create another contact which invokes ............

I think you should get the idea.

That's an obvious one, but less obvious is where a trigger update another record that has a trigger that then fires to update the first record.
For example, a trigger on contact that counts all contacts and update the parent account with that number, and a trigger on the account which when updated then updates the contacts..... and so on.

You can also get it in VF pages, which when invoked, can initialize there members which can then invoke again and so on.

If you check this post, there is quite a good explanation on recursions and it's risks and benefits by sfdcfox
https://salesforce.stackexchange.com/questions/202079/system-limitexception-maximum-stack-depth-reached-1001-error-message

Regards
Andrew
 
Rob Koch 1Rob Koch 1
Thank you, Andrew. I set a 1000 limit in the controller and that worked to resolve the error.