You need to sign in to do that
Don't have an account?
error: SELF_REFERENCE_FROM_TRIGGER while updating child records
Hi,
What I am trying to do is like this. I have an object Quote__c and it has child Quote_Line__c. When I update the currency fields in quote__c it has to update the currency field in the children .So ,in the before update trigger of Quote__c I am trying to update the currency fields in children.But in the Quote__c I have some rollup summary fields. So consequently when the child object get updated it try to update the rollup summary fields in Quote__c(master).As a result it caught in the error
System.DmlException: Update failed. First exception on row 0 with id a0dA0000000rAw4IAE; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = a0fA0000000ki1a) is currently in trigger ChangeQuoteCurrency, therefore it cannot recursively update itself: []
I tried some methods but I did not get success. I tried This option without any success.
Thanks
Samarjit
thanks for your reply forcedotcom.
What you are suggesting is already there in my code. I am executing the trigger code and update the children only if the currencyISOCode has changed,yet the child record try to update master record for rollup summary field.
Anyway I have been able to solve my problem.My fault was, I try to update the children in before update trigger,so the rollup summery try to update the same record before update .There it caught the error.So I change the master record trigger to after update and implement the static variable concept to prevent the recursive calling,that solved my problem. :)
All Answers
Hi Samarjit - I would recommend that you compare the trigger.old & trigger.new values so that your child record updates only occur when the value of the CurrencyISOCode has been changed. This should help the constant loop you're experiencing.
thanks for your reply forcedotcom.
What you are suggesting is already there in my code. I am executing the trigger code and update the children only if the currencyISOCode has changed,yet the child record try to update master record for rollup summary field.
Anyway I have been able to solve my problem.My fault was, I try to update the children in before update trigger,so the rollup summery try to update the same record before update .There it caught the error.So I change the master record trigger to after update and implement the static variable concept to prevent the recursive calling,that solved my problem. :)
Hi Samar,
I had unknowingly fallen in this trap with my Master SObject having an rollup summary field.
I had originally constructed an after update trigger on the Master SObject which used to add data in the Child SObject.
When data was updated in Master SObject, i saw multiple records getting created with same data in my Child SObject, all having same information and i started getting Too many save points error.
So to debug the above problem, i then change the trigger definition to before update.
It started giving me the error row 0; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id =....
In troubleshooting above error, we discovered that a roll-up summary field exists between Master and Child SObjects.
We searched Salesforce user forums and were lucky to find your comments.
I just did not understand 'static variable concept' from your previous comments (dated
), so i request you to explain it here, so that some day it would benefit some one;....So I change the master record trigger to after update and implement the static variable concept to prevent the recursive calling,that solved my problem...
NOTE : To represent Master-Child relationship, i have explicitly used specified SObjects with dummy names Master Child.
VM10,
The concept is like this,
1. Write a class with a static boolean varible with default value true.
2.In the trigger , before executing your code keep a check that the vaible is true or not.
3.when you'll check make the vaible false.
For example:
In the class
In the trigger
Hope you got my point.
Reagrds,
Samarjit