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
EtienneCoutantEtienneCoutant 

Maximum trigger depth exceeded on a non recursive trigger

Hi,

I created a trigger on Tasks, so that whenever a Task is created it adds the score associated to the task to the related Contact/Lead.

Here is the code of the trigger:
Code:
trigger addActivityScore on Task (after insert) { 

for (Task activity:Trigger.new) { 
   if (activity.WhoId != null && (''+activity.WhoId).startsWith('00Q')) 
   { 
      Lead lead = [select Id, Activity_Score__c from Lead where Id =: activity.WhoId limit 1]; 
      if(lead.Activity_Score__c == null) lead.Activity_Score__c = 0; 
      lead.Activity_Score__c += activity.Activity_Score__c; 
      update lead; 
   } 
   else if(activity.WhoId != null && (''+activity.WhoId).startsWith('003')) 
   { 
      Contact contact = [select Id, Activity_Score__c from Contact where Id =: activity.WhoId limit 1]; 
      if(contact.Activity_Score__c == null) contact.Activity_Score__c = 0; 
      contact.Activity_Score__c += activity.Activity_Score__c; 
      update contact; 
   } 
  } 
} 

When I pushed this trigger on production, it worked until someone filled the Web-To-Lead form, that comes out of the box with Salesforce.com
Then I received error messages from both the Apex code, and the Web-To-Lead queue, with the following error:

  • From the Web-To-Lead queue:
Alert: Salesforce experienced the following problem creating the lead below:

Reason: common.apex.TriggerExecutionException: Apex trigger addActivityScore caused an unexpected exception, contact your administrator: addActivityScore: maximum trigger depth exceeded

  • From the Apex code:
Reason: common.apex.TriggerExecutionException: Apex trigger addActivityScore caused an unexpected exception, contact your administrator: addActivityScore: maximum trigger depth exceeded

I am not sure why I am getting a maximum trigger depth exceeded exception as the trigger is not reccursive. Can someone help?

 
Thx
Etienne
David VPDavid VP
Isn't it so that when a web-to-lead comes in, it will automatically create a follow-up task ? (I know mail2case does it for example).

You might have something going on there with the lead/task updates that gets in a loop ... ?


David



EtienneCoutantEtienneCoutant
Hi David,

The Web-To-Lead does create a Task attached to the created Lead, because an auto-response email is sent out to the Lead. However the workflow should still be:

User submits Web-To-Lead form --> Lead placed in a queue at Salesforce --> Lead created --> Auto-response sent --> Task created to reflect auto-response --> Lead's score updated

Is there something i am missing?

Etienne
David VPDavid VP
I would agree with you ...I don't see immediately what the problem is either. I assume you checked that no other workflow rules or triggers are causing this ...

I'm a bit short on time to try it out right now but I'm sure someone will beat me to it ??


-david-