You need to sign in to do that
Don't have an account?
pdo
Governor Limits on Trigger
Hi All,
I am trying to update a field (practiceid__c) on child accounts of a parent account when the parent is updated. Unfortunately I hit the governor limits because for some reason, the trigger iterates through all my accounts and not just the ones associated with my trigger. How do I confine the update to only the children of the account I am updating? Here is my simple trigger:
trigger wfpracticeid on account (after update) { list<account> children = [select c.parent.practiceid__c, c.practiceid__c from account c where parentid in :trigger.new]; for (account child :children) { child.practiceid__c = child.parent.practiceid__c; } update children; }
Here is an article on how to handle recursive triggers: http://developer.force.com/cookbook/recipe/controlling-recursive-triggers
My code ended up looking like this:
Trigger
Class:
All Answers
Quick update to optimize the code, but I still hit the governors:
U write a trigger on account & update the account so it run's Recursly
Do u have diffrent record tyoe for parent & child record on account if yes then
u can try this
If u don't have record type if have another sol to stop the Recursive trigger
Hi
Prior replies address valid issues in your process.
additionally, consider that a 'child' could be someone elses parent - you need to address that logicaly before
you go to the technical side
Hi SRK, I tried your suggestion, but am still hitting limits. Here is my updated code:
Okay, so I figured out that I had a trigger triggering a trigger causing the Governor Limits so I tried combining them tinto one. I have a few roll ups and some other stuff going on, but I am still hitting the limits. Any advice?
U r updating "children" which is again a account
so u need to figure out a way that u r trigger run only when parent account is update.
if parent & child both have diffrent recordtype u can put the recprdtype check o top so it won't run for child accuounts
Hi SRK, I have made another attempt and resolved that issue, but now am getting too many SOQL queries. All I want to do is query the children of the Account I am updating so I don't understand why I am getting a query limit now.
Here is an article on how to handle recursive triggers: http://developer.force.com/cookbook/recipe/controlling-recursive-triggers
My code ended up looking like this:
Trigger
Class: