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
Mike FitchMike Fitch 

Assigning a Record Type to a Validation Rule

I created a validation rule on the opportunity object that limits the Probability % field to certain values. I need to make this rule active for a particular record type. I need help with the syntax in order to do this. Here is the formula:

OR(
AND(
ISPICKVAL(StageName,"Closed Lost"),
Probability <> 0),
AND(
MOD(Probability*100,10)<>0,
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
OR(
Probability = 0.5,
Probability = 0,
Probability = 1),
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
ISPICKVAL(StageName,"Closed Won"),
Probability <> 1)
)

Best Answer chosen by Mike Fitch
Vinit_KumarVinit_Kumar
Mike,

Try below code :- 
If((RecordTypeId='<Id of RecordType>'),OR(
AND(
ISPICKVAL(StageName,"Closed Lost"),
Probability <> 0),
AND(
MOD(Probability*100,10)<>0,
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
OR(
Probability = 0.5,
Probability = 0,
Probability = 1),
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
ISPICKVAL(StageName,"Closed Won"),
Probability <> 1)
),null)
If this helps,please mark it as best answer to help others.

All Answers

Daniel B ProbertDaniel B Probert
put an iff at the beginning that refers to the RecordTypeId

if(RecordTypeId = 'sf code'), you code, null)
Mike FitchMike Fitch
Should I put the IF statement at the very beginning before the OR statement? Also what did you mean by "you code, null)"? I apologize but I'm new to salesforce development.
Daniel B ProbertDaniel B Probert
yes so what i meant is:

IF(RecordTypeID = 'sf code'),
OR(
AND(
ISPICKVAL(StageName,"Closed Lost"),
Probability <> 0),
AND(
MOD(Probability*100,10)<>0,
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
OR(
Probability = 0.5,
Probability = 0,
Probability = 1),
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
ISPICKVAL(StageName,"Closed Won"),
Probability <> 1)
), null)


Mike FitchMike Fitch
Ok I understand. May I ask what the null statement is for? I'm sure that's the proper syntax, I would just like to understand why it's needed. Like I said I'm fairly new to this :)
Daniel B ProbertDaniel B Probert
just say don't do anything if the recordtypeid doesn't match..
Mike FitchMike Fitch
Ok that makes perfect sense now. Thank you so much for your help!!! 
Daniel B ProbertDaniel B Probert
no worries glad i could help..
Mike FitchMike Fitch
I tried the code you suggested and I'm getting a syntax error saying there's an extra ',' after the IF statement.
Vinit_KumarVinit_Kumar
Mike,

Try below code :- 
If((RecordTypeId='<Id of RecordType>'),OR(
AND(
ISPICKVAL(StageName,"Closed Lost"),
Probability <> 0),
AND(
MOD(Probability*100,10)<>0,
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
OR(
Probability = 0.5,
Probability = 0,
Probability = 1),
!ISPICKVAL(StageName,"Closed Lost"),
!ISPICKVAL(StageName,"Closed Won")
),
AND(
ISPICKVAL(StageName,"Closed Won"),
Probability <> 1)
),null)
If this helps,please mark it as best answer to help others.
This was selected as the best answer
Daniel B ProbertDaniel B Probert
ah yes missing ( at the beginning..
Mike FitchMike Fitch
That was it. I was missing that extra parenthesis after the IF. Thank you.