Can anyone please help with a possible solution?
I have a Workflow on the Opportunity Products (Opportunity LineItems) that has one significant issue, which I can't workout how to solve.
The workflow seems to fire when desired and updates the Sales Price ('UnitPrice') field based on a calculation and certain criteria, BUT it is always one step behind i.e. it updates with the correct answer for the previous calculation, so if I then just 'Edit All' and re-save without amending anything it then has the correct answer (kind of catching up so to speak). The formula uses a custom roll-up summary field, which is a subset value of the total Amount on the related Opportunity object. What I think is happening is that the workflow is taking the Roll-up summary value before it is updated by the new total value of all the Opportunity LineItems and as a result it is applying the prior value.
Thank you in advance of your help,
Jonny
Best Answer
The roll-up summary field is only updated after the field updates, triggered by your workflow rules, have been completed. See Triggers and Order of Execution.
I'm not aware of a workaround which you could implement, without using code. So have a go at adapting the below.
Note - This is an After trigger because changing the Opportunity Product's
UnitPrice
will cause the OpportunityAmount
field to recalculate, causing the recursive trigger error.This will update the Sales Price of all Opportunity Products which are related to the Opportunity which has just had it's roll-up field update. I'm guessing that that's what you'll want but if not, let me know.
Trigger
Test Class