Ask Search:
Heidi BroseHeidi Brose 

Validation Rule based on Record Type

I'm trying to create a formula that only fires for one specific record type but all record types are getting an error to require this field.  

This is my formula:
 
AND( 
OR( 
$RecordType.Id = "012600000000ldi", /*TECHSUP*/ 
ISPICKVAL( Client_Follow_up_Required__c,"" ), 
ISPICKVAL(Status, "Closed")))

I'm using a nearly idental formula for a validation rule for a different record type, and it works correctly.  Thanks in advance!


Best Answer chosen by Moderator (salesforce.com) 
Steve MolisSteve Molis
Personally I would use Name instead of ID, anyway here's 2 Flavors you can try: 

Chocolate:

AND( 
$RecordType.Name = "The RecType Name", 
ISBLANK(TEXT(Client_Follow_up_Required__c)), 
ISPICKVAL(Status, "Closed"))

Vanilla:

AND( 
$RecordType.Id = "012600000000ldi", 
ISBLANK(TEXT(Client_Follow_up_Required__c)), 
ISPICKVAL(Status, "Closed"))
 
 

All Answers

Steve MolisSteve Molis
Personally I would use Name instead of ID, anyway here's 2 Flavors you can try: 

Chocolate:

AND( 
$RecordType.Name = "The RecType Name", 
ISBLANK(TEXT(Client_Follow_up_Required__c)), 
ISPICKVAL(Status, "Closed"))

Vanilla:

AND( 
$RecordType.Id = "012600000000ldi", 
ISBLANK(TEXT(Client_Follow_up_Required__c)), 
ISPICKVAL(Status, "Closed"))
 
 
This was selected as the best answer
Heidi BroseHeidi Brose
Thanks Steve, those do work and I found another way to write it as well.  Any idea though, why the ISPICKVAL( Client_Follow_up_Required__c,"" ) doesn't work? 
Steve MolisSteve Molis
I'm not sure why it wouldn't work, I just like to use ISBLANK when I'm testing for empty fields instead of comparing it to "" just in case of a typo, or the occasional issue with the text formatting og the quotation marks if you copy&paste your formula.
Heidi BroseHeidi Brose
Fair enough, and it must have been a typo because now it seems to work just fine.  Thanks again for your help.  

Safe Harbor! 
John GarvensJohn Garvens
Out of curiosity, why did you use "$RecordType.Name" instead of "RecordType.Name"? I am new to coding with Apex. Thanks for your insights!
Peggy GriffinPeggy Griffin
'$' indicates RecordType is a global variable (since it comes 'out of the box' with Salesforce).
Dmitri GoncharovDmitri Goncharov
$RecordType.Name did not work for me. However, the $RecordType.DeveloperName = "WHATEVER NAME FOR YOUR RECORD TYPE" worked just fine.

User-added image

 
Zahra BukhariZahra Bukhari
Super helpful, thank you @Steve Molis!!!
Danielle GalianoDanielle Galiano
Hello! I figured I would jump in on this thread since I have a very similar problem. My formula has many dependencies. It follows the same as above but with two additional requirements:
So if a record type is X OR a multi select picklist has X value, then another field needs to be required. THEN if that field has a certain value, another field needs to be required. I wrote it out like this for opportunity records:

If record type is "CMS Child" OR CMAG Division is "CMS"
Public Company needs to be Required
If Public Company is YES, Public Company Stock Ticker needs to be Required

I started my formula like this: 
IF(
AND(
OR(RecordType.Id = "012C0000000GK87",
INCLUDES(CMAG_Division__c , "CMS")
)),
ISPICKVAL(Public_Company__c,""), ""))

to at least get the one picklist to be required but am now thinking i need a CASE function to achieve all the necessary requirements. Is this doable through validation at all? I am thinking it might be bigger then this but am not sure. 
Emily WalsdorfEmily Walsdorf
I'm also trying to do this, but mine is still not requiring the field.  Is it because the field I want to require is a picklist?

And ( 
$RecordType.Name = "Sales",
ISBLANK( "Lost_Reason_emily__c"),
ISPICKVAL(StageName, "Closed - Lost"))
Praveen EttamPraveen Ettam
It worked for me with $RecordType.DeveloperName = "XXXXXXXXXX", I tried with Id and Name but no luck.
April WardApril Ward
THANK YOU once again SteveMo!! I've been struggling with similar validation rules for 2 hours. I OWE YOU A BEER!!
Mike ArthurMike Arthur
Re Dmitri's comment, Jan 28, 2016,

$RecordType.Name matches with 'Record Type Label' and
$RecordType.DeveloperName matches with 'Record Type Name'

Not confusing at all!
Khushboo VaidyaKhushboo Vaidya
Thanks Mike for easy bifurcation. This simple info shall help resolving many Recordtype related issues/queries.
Lewis HowelLewis Howel
Hi all,

I'm using the first part of the best answer, but I want the validation to occur if the record type name is one of two choices. How do I edit the formula to run true if it is "record type 1" OR "Record tpe 2"?
Christina MooreChristina Moore

@Lewis Howel - Have you tried? 

OR($RecordType.Name = "RecType 1" , $RecordType.Name = "RecType 2")

Jyothi MakamJyothi Makam
This is not working 
Jyothi MakamJyothi Makam
Here is my code 
AND(
ISPICKVAL(C4G_Income_Type__c = "Other"),
 ISNULL(C4G_Income_Notes__c))

This is not working Can you one help

 
Mike ArthurMike Arthur
Replace = with , in Income Type line