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
mauricio.ramos@corpitalmauricio.ramos@corpital 

Issue with Discount Amount and Percent (scale) in OpportunityLine

Hello,

 

I have come across an issue I am struggling to solve but not sure how to approach a solution. The issue is as follows:

 

I have a Vf page that mimics the Multi Product page (the one that is used to add products to an Opp). The main difference is that I also give users the option to enter Discount AMount then recalculate the discount percent so when saving to the database SF will calculate the total price. BUT I have come across an issue when entering a discount amount that translates to a discount percent with more than 2 digits of scale (for example: 365-235 will yield 39,16666666666664%, but SF rounds up to 39,17). This causes an issue because when I save the record to the database the auto calculated total price is 364,98 and not 365. This is because when SF rounds up to 39,17 it translates to 235,02 as the amount discounted.

 

Does anyone know how to  work around this issue?

Hengky IlawanHengky Ilawan

Hi,

 

What data type do you use to store the percentage?

If you use Percent as the data type, try increase the decimal places to at least 4 digits, I think it will solve the issue.

 

I am curious, why do you need to convert the input amount to percentage instead of just storing the exact amount itself?

 

-Hengky-

mauricio.ramos@corpitalmauricio.ramos@corpital

The percentage is stored to the Discount (std field) in the Opportunity Line Item, this field is standard and CANNOT have its scale increased to 4 or any other value since it is not editable. So SF will forcefully round any greater scale to a two decimal place.

 

If I just update the Total Price based on the amount to discount it will recalculate Unit Price to adjust, and this is not the desired behavior.