You need to sign in to do that
Don't have an account?
cambart14
Change Status on Projects when Opportunity is Closed
On some of our Opportunites we can have multiple 'active' projects that we would like change the status to 'complete' when its opportunity is marked as 'Won' or 'Lost'. I have looked at doing this through the Workflow, but it does not seem robust enought to accomplish this. Would I be able to accomplish this through a trigger? If not, any other suggestions are welcome. Thanks for your help!
Hi,
Here your code :
All Answers
if the status will become complete on the project (object which is seperate from opportunity other than just a field ) and you are expecting the field update on the opportunity object that doesnt work ,
The reason is workflows did not support the crosss functional objects.
If above assumptions or the guess is right then you should write a trigger
If this answers your question make this as solution
Hi,
This can be easily done with trigger.
Write "after Insert" trigger and check whether the status of Opportunity is 'Won' or 'Lost'. If condition meet then get list of all child / related project and update there status also.
Jitendra, you're comment has been most helpful, although I sitll need a bit more direction and help with the trigger.
I have outline below what I want the trigger to do, but I'm not sure where to start to have it get a list of all child/related projects.
Any help on this would be great, thank you!
Hi,
If your opportunity is marked as "Won" or "Lost", when this opportunity created, you can create a "after insert" trigger.
If your opportunity has another status when it created, then after some operates, you change the opportunity from its origional status to "Won" or "Lost", in this scenario, craete a "after update"
Thank you!
I have written a trigger to try and update the related custom object, but I keep getting this error Error: Initial term of field expression must be a concrete SObject: Id at line 8 column 6. My code is below:
Hi,
As your code, the list ProductsToUpdate's type is Project__c,so if you want to loop this list, you need change ol type to Project__c.
Try this :
Jitendra and WEN JIE,
Your suggestions got rid of the error message, but the trigger still doesn't seem to updated the related Project objects. I have tried editing the Opportunity in several different ways, but the Project status never updates. I'm not sure what is missing...
Hi,
I think you can add some system.debug in your trigger then can see some values in Debug Logs and check the detail.
Actually ,I don't think you need to use Set. And your Status__c is the opportunity id??? Please check your SOQL.
Thank you!
Thanks for your suggestions JIE. I am new to programming in Salesforce, so I'm sure there are several big mistakes in my code. I have changed my SOQL, but still not quite sure if it right.
I have found another example of updating related child fields (see revised code below). I'm wondering if this would be more effective at trying to accomplish my task?
Thanks again!
Hi,
Here your code :
Jitendra! That worked great, thank you! I made a few revisions to the code (see below), but other than that it worked great.
It's great! I also get useful info from your SOQL.