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
Frenchy52Frenchy52 

Maximum Trigger depth exceeded

I have 3 objects: Transaction Rel, Transaction and Target Client Relationship. Transaction Rel is attached as a related list to Transaction and Target Client is a lookup on Transaction Rel. Everything starts at the Traget Client Relationship level. I built some code on the Target Client Relationship object that works through  a button when I click this button I want the system to create a basic Transcation record and Transaction Rel records and attach the transaction Rel record to the Target Client Record it originates from. THis thing works beautifully in Sandabox and does exactly what I want it to do. I built the test methods and they all validate at more than 75%.  I transfered all this in Production and I now get this error message when I try to create  a Transaction or a Transaction relationship or when I when I click on the button:

 

CreateTransactionRel: maximum trigger depth exceeded Target_Client_Relationship trigger event AfterUpdate for [a067000000WCGoM] Transaction trigger event AfterInsert for [a087000000JnL27] Transaction_Relationship trigger event AfterInsert for [a0E70000008CS6R] Target_Client_Relationship trigger event AfterUpdate for [a067000000WCGoM] Transaction trigger event AfterInsert for [a087000000JnLZ9] Transaction_Relationship trigger event AfterInsert for [a0E70000008CS6S] Target_Client_Relationship trigger event AfterUpdate for [a067000000WCGoM] Transaction trigger event AfterInsert for [a087000000JnLZA] Transaction_Relationship trigger event AfterInsert for [a0E70000008CS6T] Target_Client_Relationship trigger event AfterUpdate for [a067000000WCGoM] Transaction trigger event AfterInsert for [a087000000JnLZB] Transaction_Relationship trigger event AfterInsert for [a0E70000008CSeV] Target_Client_Relationship trigger event AfterUpdate for [a067000000WCGoM] Transaction trigger event AfterInsert for [a087000000JnLZC] Transaction_Relationship trigger event AfterInsert for [a0E70000008CSeW] Target_Client_Relationship trigger event AfterUpdate for [a067000000WCGoM]

 

 

To achieve this I have 3 steps:

 

1-I created a button with  a link that triggers the first trigger

 

2-Trigger on the Target Client Relationship record:

 

 

trigger CreateTransaction on Target_Client_Relationship__c (after insert, after update) {

    
    List <Transaction__c> tranToInsert = new List <Transaction__c> ();  
    
    
    for (Target_Client_Relationship__c o : Trigger.new) {
        
        
       
        if (o.Type__c =='YES') {  
        
        Transaction__c v = new Transaction__c ();
        
        
        v.target__c = o.Target__c;
       
        v.Transaction_Headline__c = o.Target_Name__c+ ' received an investment by '

+o.Related_Company_Name__c ;
        
        v.Transaction_Press_Release_Text__c = 'No further information is available on this investment.  

Please feel free to submit additional information on this transaction using the "Suggest Transaction

Update" button above.';
        
        v.TCRID__c= o.TCRID__c;
        
        v.RelatedCoID__c= o.Related_Company_ID__c;
        
        v.Trigger__c= o.Type__c;
        
        v.Record_Status__c='New';
        
        v.Transaction_Status__c='Closed';
        
        v.No_PR__c=true;
        
        tranToInsert.add(v);
        
        
        }
        
    }
   

 

 

 

 

 

3- Trigger on the Transaction record that creates the Transcation Rel

 

 

trigger CreateTransactionRel on Transaction__c (after insert) {

    
    List <Transaction_Relationship__c> TRToInsert = new List <Transaction_Relationship__c> ();  
    
    
    for (Transaction__c o : Trigger.new) {
        
        
       
        if (o.Trigger__c =='YES') {  
        
        Transaction_Relationship__c v = new Transaction_Relationship__c (); 
        
        v.Transaction__c = o.TransID__c;
        
        v.target__c = o.Target__c;
       
        v.Name = o.Target_Name__c+' Financing'; 
        
        v.Target_Relationship__c = o.TCRID__c;
        
        v.Related_Company__c = o.RelatedCoID__c;
           
        
        TRToInsert.add(v);
        
        
        }
        
    }

 

 

Why is this code working in Sandbox and not in Production?

Chamil MadusankaChamil Madusanka

Please study this post.

 

http://boards.developerforce.com/t5/Apex-Code-Development/error-maximum-trigger-depth-exceeded/td-p/55710

 

It has same issue "Maximum Trigger depth exceeded". Normally, this issue is occurs when you insert/ update some object instance in same object trigger(after insert/after update).

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Navatar_DbSupNavatar_DbSup

Hi,

 

You are getting this error because your trigger recursively calling himself. So to overcome with that you have to declare a static variable (Boolean type) in another class and make certain criteria based on that static variable inside your trigger. Please go through this link for more details:

 

http://developer.force.com/cookbook/recipe/controlling-recursive-triggers

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.