You need to sign in to do that
Don't have an account?
Benny Stevens 1
Trigger OLI after updating parent Opportunity record
Hi,
I have configured WFR Email Alerts on Opportunity Line Items (Opportunity Products) that sends email notifications when certain criteria are met.
The WFR works fine, but the criteria also includes conditions for the Opportunity, so, the WFR on Opportunity Product doesn't work when the parent Opportunity is being updated.
That's why I would like to add a trigger on the Opportunity that updates all related Opportunity Products (OLI's). It is only necessary for one specific record type (called "EU Opportunity") and it should not update any specific information on the OLI, I only want the "last modified date" to update and then WFR Email Alerts will work if the conditions are met.
1) Would this be a good solution for my situation?
2) I have tried to right a trigger and test class, but was not able to do it. Could someone please help me?
Please let me know if you'd require further information.
Many thanks in advance,
Benny
I have configured WFR Email Alerts on Opportunity Line Items (Opportunity Products) that sends email notifications when certain criteria are met.
The WFR works fine, but the criteria also includes conditions for the Opportunity, so, the WFR on Opportunity Product doesn't work when the parent Opportunity is being updated.
That's why I would like to add a trigger on the Opportunity that updates all related Opportunity Products (OLI's). It is only necessary for one specific record type (called "EU Opportunity") and it should not update any specific information on the OLI, I only want the "last modified date" to update and then WFR Email Alerts will work if the conditions are met.
1) Would this be a good solution for my situation?
2) I have tried to right a trigger and test class, but was not able to do it. Could someone please help me?
Please let me know if you'd require further information.
Many thanks in advance,
Benny
https://developer.salesforce.com/forums?id=906F000000093RaIAI
All Answers
Thanks for your quick respons jjbenneett530. OK, a new (hidden) field to update would not be an issue.
In my example the WFR Email Alert on Opportunity Product is triggered when the Opportunity has the Record Type = 'EU Opportunity' AND Stage is Quotation and when the Opportunity Product has a UnitPrice > 10.
Now, when the Opportunity Stage is moved to Quotation (while it is an EU Opportunity and UnitPrice > 10) the WFR won't work. How should the trigger look like with the new custom field on Opportunity Product?
Hi,
I tried to write my trigger and test class (I am just starting as an admin) based on the following blog post:
http://knthornt.wordpress.com/2011/07/29/updating-products-on-opportunity-close-date-change/
I wanted to start the trigger in case of changes in the Stage. I created a Stage field on OLI (Opp Product), the trigger should update the picklist whenever it is changed on the Parent Opportunity.
The trigger is working, that's great, but I can't right the test class and therefor I am not able to push it into Production.
Could the issue be that the error/issue is related to (old) API version? (blog post is from 2011/07/29). I already added "(SeeAllData = true)" but not solved yet ... Failed Class Test, but code coverage is 43% (7/16)
Thanks, Benny
My trigger:
My test class:
The error:
Thanks, Benny
Hi jjbennett530, so you have added the exact same APEX Trigger and Test Class and it worked for you? Did you get 100% (16/16) code coverage?
Thanks for the link, I wanted to log a case also, but I got the message that I should get support on this forum for developer support :-)
(Assistance with Developing (coding, APEX, visualforce: "Developer support for standard customers and partners is supported directly through our community. If you have a developer support question, please visit our Developer Forum")
//Get the record type we care about plus 3 other ones.
List<RecordType> recTypeList = [select Id, Name from RecordType where (Name='test' OR Name='test2') AND SobjectType='Opportunity'];
https://developer.salesforce.com/forums?id=906F000000093RaIAI
I have deactivated the WFR on OLI which updates the Quantity field with the value of another number field.
I was able to get a passed test and 100% code coverage!
I updated the WFR field update with the criteria that the number field should be greater or equal to 1, before it can be triggered.
I have activated the WFR again, and ran a succesfull test.
Thank you so much for your time and efforts!