You need to sign in to do that
Don't have an account?
Tommy C
How to update a parent record in a trigger if the parent record is the same kind of object as the child object being triggered?
Hi all,
I have some code that I would like to ensure updates from the child Opportunities to the parent Opportunity, which is a renewal. Right now, I have a beforeUpdate trigger that looks to see if the Opportunity has any children opportunities. If it does, then it will sum up the values of Currency1__c, Currency2__c, and Currencye3__c from the child opportunities into the parent's Opp fields rollupCurrency1,rollupCurrency2 , and rollupCurrency3. I have this part written out.
The second part is a little difficult for me to figure out. Essentially, I want it so that if any of three specific Currency fields are changed on the child opportunity, it should trigger an update in the parent Opportunity. They are associated via a lookup field. Since it's the same object, I'm not sure what the best practice would be to update the parent Opportunity when the Opp Trigger is triggered from the child Opportunity since it's not passed in Trigger.New, and DML operations don't work on the same object if I recall correctly. Any help is appreciated!
I have some code that I would like to ensure updates from the child Opportunities to the parent Opportunity, which is a renewal. Right now, I have a beforeUpdate trigger that looks to see if the Opportunity has any children opportunities. If it does, then it will sum up the values of Currency1__c, Currency2__c, and Currencye3__c from the child opportunities into the parent's Opp fields rollupCurrency1,rollupCurrency2 , and rollupCurrency3. I have this part written out.
The second part is a little difficult for me to figure out. Essentially, I want it so that if any of three specific Currency fields are changed on the child opportunity, it should trigger an update in the parent Opportunity. They are associated via a lookup field. Since it's the same object, I'm not sure what the best practice would be to update the parent Opportunity when the Opp Trigger is triggered from the child Opportunity since it's not passed in Trigger.New, and DML operations don't work on the same object if I recall correctly. Any help is appreciated!
Inside the handler you need to retrieve the parent opportunity with a soql and then update it.