You need to sign in to do that
Don't have an account?

trigger to update opportunity stage from child object
I need help in writing a trigger, I have two objects
1) Opportunity
2) Opportunity_ Program__c
both are having lookup relationship, Opportunity is Parent and Opportunity Program is child.
Opportunity program has Status field.
I need to write a trigger on Opportunity Program object, for a given Opportunity if any of the child records contains status as "MATR" then Opportunity.StageName = 'Closed Won', if any of the child record for a given opportunity does not contain "MATR" then Opportunity.StageName = 'Closed Lost'
Can anyone helps me out in this issue please.
1) Opportunity
2) Opportunity_ Program__c
both are having lookup relationship, Opportunity is Parent and Opportunity Program is child.
Opportunity program has Status field.
I need to write a trigger on Opportunity Program object, for a given Opportunity if any of the child records contains status as "MATR" then Opportunity.StageName = 'Closed Won', if any of the child record for a given opportunity does not contain "MATR" then Opportunity.StageName = 'Closed Lost'
Can anyone helps me out in this issue please.
Would it work with your business process if the trigger on Opportunity Program, on update, checks to see if the Status contains 'MATR' and if so simply changes the status of the Opportunity to 'Closed Won'? And then vice versa, if an Opportunity Program Status is changed to not contain 'MATR', then the Status of the Opportunity is changed to 'Closed Lost' (if not already 'Closed Lost').
Do you have more than one picklist value on the Status field that contains 'MATR'? Or would the value that you are checking against simply be 'MATR'?
You can try this code this will help you.
You need to change the field API names according to your fields.
If you found it useful please appreciate my efforts and mark it as the best answer
Regards,
Soyab
Thanka a lot for helping me out here
If any of the status of Opportunity program contains 'MATR' then stageName= closed won
If none of the status of Opportunity Program contains 'MATR' but contains either 'WADM' or 'WAMM' then stage should be closed lost
else if opportunity program for a particular opportunity contains 'DENY' or 'LITE' THEN STAGE SHOULD BE OPEN
Use this code maybe this will help you.
Regards,
Soyab
I have understood you requirment and tried to find out the solution. I believe it will help you.
I have given below solution for the conditions-
1. Opportunity_ Program__c has a lookup for Opportunity.
2. Opportunity_ Program__c record has a status field.
That's all if you have more queries please let me know.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
I have gone through made the same object and trigger it is working correctly.
Trigger to update the opportunity with is child item is given below:-
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com