function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hwebster82hwebster82 

How to Update the Opportunity Product Sales Price on Opportunity Save?

Problem: Need to update the Amount field on Opportunity to use forecasting. 

 

Solution: Created a field update on the product (since product sales price trumps field updates on opportunities) to update a formula field found on the opportunity.

 

New Problem: When opportunity detail is modified (i.e. the formula value changes based on inputs from rep) the product field update isn't updated.  It's only updated when you modify the product.

 

This where I need help.  Is there a way to "save/modify" the product when the opportunity is saved? Is the solution I need to make the product update a Trigger?  If so, when I create this trigger, do I have to write a class as well?

 

All help/direction is appreciated!  If anyone has other suggestions, I'm open to trying them as well!

 

Thanks!

hwebster82hwebster82

This is what I have....but it's not updating the opportunity line item. Am I going in the right direction?  Am I updating a field correctly?  I guess this is the disadvantage of not knowing code. :(

 

trigger Product_Update on Opportunity (after update) {

 

//Using Last Opportunity Update field as a way to push an "update" List<OpportunityLineItem> Product = [SELECT Id, Last_Opporunity_Update__c FROM OpportunityLineItem // This is where I get an error message. I thought I needed to link the opportunity to the opporutnity line item. WHERE OpportunityLineItem.OpportunityId = :Opportunity.Id ]; for(OpportunityLineItem o:Product) {o.Last_Opporunity_Update__c = system.today();} update Product; }