2

I want to create a validation rule at Opportunity product to validate the following. Opp record Type – sample And Stage not equal to ‘Pending Approval’ Product or product code(item number) ends with -22 or -23 or -24
Then you it should give the following error message. When requesting samples for 130 Lumen parts, stage should be pending approval

Validation rule as :

( 
(Opportunity.RecordTypeId = "012d0000000l8YP" ) && 
(Not(ispickval(Opportunity.StageName,"Pending Approval")) )&&
if(Product2.ProductCode == "XXXX22" || "XXXX23"|| "XXXX24") errormsg ,false)

but i do get an Error as : Incorrect parameter type for function 'or()'. Expected Boolean, received Text. How to give the product code which ends with 22 ,23,24.

Any suggestion plz.Thanks in advance.

6
  • @Uwe Heim:Thanks for your reply.I have created a record by selecting the record id ,giving the stage name as 'qualification',selected the product code whc ends with 22 ,But it does not throw any Error msg.As per my validation rule it should throw an Error Msg.Is that i have made any mistake im ky Validation rule
    – nikkey
    Dec 2, 2014 at 10:10
  • As you do not provide new code for what you have updated, it's impossible to answer this question. The code I see here can't work as stated in my answer below. Please look carefully at the REGEX() function and test it isolated without any AND and OR just to see, that it fires as expected. Then step-by-step add your AND and OR logic until you have all you need in the very end. Don't do it all at once please, as you have a hard time to debug it.
    – Uwe Heim
    Dec 2, 2014 at 13:18
  • @Uwe Heim:( (Opportunity.RecordTypeId = "012d0000000l8YP" ) && (Not(ispickval(Opportunity.StageName,"Pending Approval")))&& if(Product2.ProductCode == "XXXX22" ||Product2.ProductCode == "XXXX23"||Product2.ProductCode == "XXXX24",true,false))
    – nikkey
    Dec 2, 2014 at 15:51
  • XXXX23 will never work. As I said earlier, you'll need to look at REGEX() or if this is too hard, you might go with RIGHT(), following this pattern here: success.salesforce.com/answers?id=90630000000gkXIAAY
    – Uwe Heim
    Dec 2, 2014 at 16:19
  • @Uwe Heim: i tried something using Right (),but no result as expected.Can u plz help me out( (Opportunity.RecordTypeId = "012d0000000l8YP" ) && (Not(ispickval(Opportunity.StageName,"Pending Approval")))&& (Not(CONTAINS( RIGHT(Product2.ProductCode, 2) , "22")|| (CONTAINS( RIGHT(Product2.ProductCode, 2), "23")|| (CONTAINS( RIGHT(Product2.ProductCode, 2), "24") )) is this the correct way im usin the Right().
    – nikkey
    Dec 2, 2014 at 17:34

2 Answers 2

0

This is the problem

if(Product2.ProductCode == "XXXX22" || "XXXX23"|| "XXXX24")

You better write it like that

if(Product2.ProductCode == "XXXX22" || Product2.ProductCode ==   "XXXX23"||  Product2.ProductCode ==  "XXXX24")

But this fixes only the syntax error and your code still doesn't work. Look at the REGEX() formula function instead.

0

@Uwe Heim Thanks for your help .

I tried out sorting it out line by line and at last i can achieve the o/p .So taught of posting and it will be useful to others.

AND( Opportunity.RecordType.Name = "Sample", OR( CONTAINS(RIGHT(Product2.ProductCode, 3), "-22"), CONTAINS(RIGHT(Product2.ProductCode, 3), "-23"), CONTAINS(RIGHT(Product2.ProductCode, 3), "-24") ), Not(ispickval(Opportunity.StageName,"Pending Approval")) )

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .