You need to sign in to do that
Don't have an account?
NikiG22
Trigger - Update Fields
Hello - I am trying to update fields on thje opportunitylineitem from the Product whe a rep selects a specific product.
I have the following code but its not updating? Please help!
trigger UpdateOpportunityProductFields on OpportunityLineItem (before insert, before update){ { for(OpportunityLineItem myOLI:trigger.new) { if(myOLI.Product_Family__c == 'Resume Search') { myOLI.Views__c = myOLI.PriceBookEntry.Product2.Views__c; myOLI.Term_Days__c = myOLI.PriceBookEntry.Product2.Term_Days__c; myOLI.Daily_View_Limit__c = myOLI.PriceBookEntry.Product2.Daily_View_Limit__c; } } } }
Cheers,
Niki
thank you I did get it to work i edited this
if(myOLI.PriceBookEntry.Product2.Family == 'Resume Search')
Thanks for your help,
Niki
All Answers
I believe you have to do and update statement outside of the if statement.
Debug Log is your friend, make sure you're comparing the values you are expecting within your if statement and what is really being stored.
Hi,
@MIlliote
You cannot update any object within the same object's trigger(specially before insert and before update). If you do so you will get following error;
System.SObjectException: DML statment cannot operate on trigger.new or trigger.old
@ NikiG22
Your code is ok. but you are saying that record is not updating. There will be few reasons.
Therefore, check use the debug logs as Alex said.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
thank you I did get it to work i edited this
if(myOLI.PriceBookEntry.Product2.Family == 'Resume Search')
Thanks for your help,
Niki