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
SalesIntelSalesIntel 

IF product code = x,y,x then discount cannot exceed x%

Excited to join the group! First posting.

 

I am trying to create a validation rule that states, essentially, if product code = x or y or z...... then the discount should not exceed, say 40%. I am using all standard fields as you can see below.

 

Here's what I have come up with: Passes syntax test, but does not work (allows me to save even if discount exceeds my limit, in this case, 40%):

 

IF(OR(Product2.ProductCode= "EN-P-AW-100"),
(Product2.ProductCode= "EN-P-CCE-110"),
Discount > 0.40)

 

What am I doing wrong?

 

Thanks! :-)

Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

Welcome to the club!  When you're writing a VR you don't want to use an IF statement you want to use an AND, OR statement (the "if" is implied)

 

Try something like

AND(
OR
(Product2.ProductCode= "EN-P-AW-100",
Product2.ProductCode= "EN-P-CCE-110"),
Discount > 0.40)

 

PS.  you might need to play around the the commas or parens, I just kinda winged it.   

 

All Answers

Steve :-/Steve :-/

Welcome to the club!  When you're writing a VR you don't want to use an IF statement you want to use an AND, OR statement (the "if" is implied)

 

Try something like

AND(
OR
(Product2.ProductCode= "EN-P-AW-100",
Product2.ProductCode= "EN-P-CCE-110"),
Discount > 0.40)

 

PS.  you might need to play around the the commas or parens, I just kinda winged it.   

 

This was selected as the best answer
SalesIntelSalesIntel

Stevemo-

 

You are a rock star! Works like a charm.

 

Thanks!

 

 

SalesIntelSalesIntel

Stuck again!

 

I am using the following code to produce an error message when the Quantity for specific products (listed below) is up to 499 users and when the discount exceeds 40%. What I'd like to do is expand this code to include a number of quantity ranges, say 500-999, 1000-1500 etc, where the discount  (against the same product codes) should not exceed 45%, 50%, 60%, respectively.

 

Is there a way to do this in one code string rather than create unique validation rules? Here's what I am using...it works  for up to 499 users, and up to 40% discount:

 

AND(
OR
(Product2.ProductCode= "EN-P-MPS-100",
Product2.ProductCode= "EN-P-PC-100",Product2.ProductCode= "EN-P-CP-100",Product2.ProductCode= "EN-P-IP-100",Product2.ProductCode= "EN-P-AW-100",Product2.ProductCode= "EN-P-AWS-100",Product2.ProductCode= "EN-P-CCE-110",Product2.ProductCode= "EN-P-OC-100",Product2.ProductCode= "GE-P-MPS-100",Product2.ProductCode= "GE-P-PC-100",Product2.ProductCode= "GE-P-OC-100",Product2.ProductCode= "EN-P-ICM-200",Product2.ProductCode= "EN-P-SPPM-200",Product2.ProductCode= "EN-P-MISCA-300",Product2.ProductCode= "EN-P-MIBCA-310",Product2.ProductCode= "EN-P-MISCIT-320"),
AND(
(Quantity<= 499)),  Discount  > 0.40)

 

Put another way, how do introduce quantity ranges, each with a unique discount % against the same product codes in the same validation rule?

 

Thanks in advance for the help!