I am deploying a trigger from a sandbox to a production org. During validation it gives me "maximum trigger depth exceeded" error for some other trigger which is not part of the change set. The error points out to a line number containing insert and says CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY.

enter image description here

enter image description here When I run individual tests for that trigger in sandbox and production, they pass out with flying colors. I do not see any workflow or field update in production related to that trigger custom object which may cause this.

I dont know where I should start looking. Am I missing something here?

  • 1. Are your tests SeeAllData? – Adrian Larson Nov 12 '14 at 19:12
  • 2. Please post some code. – Adrian Larson Nov 12 '14 at 19:13
  • 3. Is this "other trigger" present in your lower environments? – Adrian Larson Nov 12 '14 at 19:14
  • 1. None of the tests have SeeAllData 2. Cannot post the code 3. The other trigger is already present in my production – codeinprogress Nov 12 '14 at 19:50
  • I don't need to know if it's in production. You stated that in your question. I need to know if it is in lower environments. – Adrian Larson Nov 12 '14 at 19:57

This looks like a Recursive Trigger issue. Usually when you have maximum trigger depth exception this means that a trigger is getting recursively fired. You can only have something recursively fire 16 times (Max Stack Depth).

This can happen if you have triggers that fire DML updates that fire triggers that in turn update the original record, triggering a recursive loop that doesn't stop.

A Unit Test may pass but its possible if you use SeeAllData or some other test permuatation it could trigger this on some occassions and not others.

First make sure you are preventing recursive triggers. It's a best practice also. :)

I presented on Dreamforce on this exact issue in 2013. Here is the video. Go to minute 14 where I talk about Maximum Depth Trigger and how to prevent recursion. https://www.youtube.com/watch?v=rCDSZ8_UpVs#t=848

Take a look at this post also: How do I control recursive Triggers with static variables and permit Mass Edit from List View

  • I wonder why this limit is never documented – Patlatus Oct 9 '15 at 16:04
  • 1
    This is documented here: developer.salesforce.com/docs/… . -> Please look at this line item: "Total stack depth for any Apex invocation that recursively fires triggers due to insert, update, or delete statements 16" – CoryCowgill Oct 12 '15 at 15:09
  • You are right. I was wrong – Patlatus Oct 13 '15 at 14:00
  • There is a similar limit of 32 (how many parameters can method have) which is not documented, looks like I confused these two – Patlatus Oct 13 '15 at 16:52
  • No worries. There are plenty of things that are undocumented. :) – CoryCowgill Oct 13 '15 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.