You need to sign in to do that
Don't have an account?
Arrow
Trigger to sync child opportunities with parent
New to triggers and trying to find a code example to do the following:
Child opportunities linked to parent opportunites on Parent_Opportunity__c lookup
If parent CloseDate or StageName changes, I would like a trigger to update all child opportuntiies
Hi,
There are two things to consider when doing this in trigger, since you are will be updating Other Opportunity Records in the Opportunity trigger and this will cause recursion of trigger..So follow these steps.
1. First create a class with static variable as below
2. Now you can use the sample code for your opportunity trigger or you can tweak it.
Here is the test calss if you need.....Please be advised that I'm only assuming the StageName values in test class and you need to modify them if its different from what I've used and You'll also need to populate any required fields or fields required by validation rules for test to Pass.
All Answers
Hi,
There are two things to consider when doing this in trigger, since you are will be updating Other Opportunity Records in the Opportunity trigger and this will cause recursion of trigger..So follow these steps.
1. First create a class with static variable as below
2. Now you can use the sample code for your opportunity trigger or you can tweak it.
Here is the test calss if you need.....Please be advised that I'm only assuming the StageName values in test class and you need to modify them if its different from what I've used and You'll also need to populate any required fields or fields required by validation rules for test to Pass.
Many thanks for your help, I did get an error which I fixed by adding a semi colon to the end of this line:
Also wondering how I could change this code so that it also worked if there were grandchild opportunities or even great grandchildren.
Do you think that is possible to do?
Once again, many thanks for providing such a complete solution.