You need to sign in to do that
Don't have an account?
EtienneCoutant
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:
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:
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
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:
Reason: common.apex.TriggerExecutionException: Apex trigger addActivityScore caused an unexpected exception, contact your administrator: addActivityScore: maximum trigger depth exceeded
- From the Apex code:
I am not sure why I am getting a maximum trigger depth exceeded exception as the trigger is not reccursive. Can someone help?
Etienne
You might have something going on there with the lead/task updates that gets in a loop ... ?
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
I'm a bit short on time to try it out right now but I'm sure someone will beat me to it ??
-david-