Update of Opportunity Line Items

  • 2
  • Question
  • Updated 3 years ago
  • Answered
When updating Opportunity Line items recaclulation of the total and unit price is done if only the quantity is changed. However if updating is done in a table component and the unitprice is displayed on the same row this is not very logical. I think this is because SKUID only updates changed values. If both unitprice and quantityt is changed the update works as expected but it only quantity is changed this means that unitprice is recalculated based on total price. There should be an option to force SKUID to always send both Quantity and Unitprice in the update. Is there a way to do this?
Photo of Peter Baeza

Peter Baeza

  • 2,868 Points 2k badge 2x thumb

Posted 6 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Official Response
As of Skuid's Banzai release (7.0+), there is a highly recommended alternative approach that does not require any JavaScript / Custom Field Renderers. 

In a nutshell, the approach is to add Model Actions. The first listens for changes to the Quantity field, and then runs a series of actions which have the effect of forcing an update to the UnitPrice field as well, even if it was not actually changed. The second listens for changes to a "TotalPriceFormula" Ui-Only Field, and when this is changed, the actual TotalPrice field is updated. All this rigamarole is necessary because if you only tell Salesforce to changes about one of these fields, then Salesforce tries to be "smart" and adjusts the other field values based on which field you changed. The only way to be absolutely sure that Salesforce will not "mess things up" is to tell it exactly which values to set for every field. 

To see exactly how this is done, I recommend examining the latest version of our OpportunityDetail sample page XML from the Skuid Sample Pages repository on Github.

This approach also has the benefit of being extensible, allowing you to incorporate additional fields into the "SalesPriceFormula" or "TotalPriceFormula" fields to accommodate more complex calculations. What's crucial to understand is that at the end of the day, to use the OpportunityLineItem you have only 4 fields to work with: Quantity, UnitPrice, Discount, TotalPrice. Salesforce has baked-in logic around these fields that you can't change --- TotalPrice = Quantity * UnitPrice * ((100 - Discount) / 100) . You can't really get around Salesforce's hard-coded formula --- all you can do is to adjust what values you pass to each of the component fields.

For instance, take the issue of pro-rating prices. We deal with this internally at Skuid. A company buys 1000 Skuid licenses in January, but then in June wants to add 500 more. To keep things on an annual schedule, we pro-rate the UnitPrice for these "Adds" Opportunities. However, to track this in OpportunityLineItems, we can't just inject a percentage field into Salesforce's hardcoded formula. What we can do, and what we do at Skuid, is to adjust the UnitPrice field to be a pro-rated percentage of the original UnitPrice based on how many months are remaining until the end of the year. To accomplish this using the framework set forth in the OpportunityDetail sample page given above, we add a Picklist field with values 1-12 to our OpportunityLineItem object, and then we adjust the SalesPriceFormula UI-only Formula Field so that it decreased the UnitPrice by the number of months remaining till annual renewal.