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
samarsamar 

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

Best Answer chosen by Admin (Salesforce Developers) 
samarsamar

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

forcedotcomforcedotcom

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.

samarsamar

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. :)

This was selected as the best answer
vm10vm10

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 08-18-2010 06:51 AM), 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.

samarsamar

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

 

public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
    if(run){
	 run=false;
	 return true;
    }else{
        return run;
    }
    }
}

 In the trigger

 

trigger myTrigger on myObject(after update) {
    if(checkRecursive.runOnce())
    {
//write your code here	        
    } 
}

 

Hope you got my point.

 

Reagrds,

Samarjit

 

 

 

Ramesh SomalagariRamesh Somalagari
Hi All I have same problem.Can you please click this link  http://salesforce.stackexchange.com/questions/43871/system-dmlexception-delete-failed-self-reference-from-trigger See the log I a have got same issue.