On a visualforce page, I am creating an opportunity and I am adding an OpportunityLineItem (opportunity product) to it.
The product2 linked to the opportunity product has a field called Maximum_Discount_in_percent_EUR__c, which is a percent field and specify the maximun discount possible.
When adding the opportunity product on the visualforce page, you can enter a discount in % (standard Discount field) or a net price (Net_Price_Discount__c). There is a validation rule preventing you for entering both.
The opportunity product has a validation rule checking if the discount is not superior to the authorized discount.
Here is the rule's formula:
AND(
NOT($User.ByPass_VR__c),
OR(
AND(
Product2.Maximum_Discount_in_percent_EUR__c <> 0,
IF(ISBLANK(Discount) || ISNULL(Discount),
(ListPrice - (Product2.Maximum_Discount_in_percent_EUR__c * ListPrice)) >= Net_Price_Discount__c,
Product2.Maximum_Discount_in_percent_EUR__c < Discount))
)
)
I have tested the NOT($User.ByPass_VR__c) line, and it is not giving me any problems.
When I enter a discount in the Discount field superior the authorized one, the validation rule worked fine and I get my error message.
But when I enter e net price in Net_Price_Discount__c inferior to the authorized one, then it doesn't work and I can save the opportunity product.
Is the problem in my formula or can it be somewhere else?
Thank you for your help
Best Answer
I actually find a solution to my problem.
I made a new separated validation rule. Because there is already a validation rule preventing you for entering a discount in percent and a net price, I don't need to check if the Discount field is blank or null. Here is the validation rules formula:
A good old divide and conquer solution ;-)