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
kjunkjun 

Validation Rule not working correctly when a recordtypeId is introduced

Hello, 

Validation Rule to stop record from saving when a picklist value is blank fires, but not on the correct stage selection.

Use case:

Opportunity Object, has 6 record types (Group, Branch, Vendor, Client, Guest, Ti In Progress)

If the Opportunity RecordTypeId is “0122E000000iFFKQA2”
and the StageName Picklist is “Ti In Progress", a value from the picklist named, Resolution Type, must have a value selected prior to saving the record. If the Resolution Type picklist is left blank, the validation rule should error out the save attempt.

The VR I created is firing but not when the stage = Ti In Progress. I can select a different stage, prior to reaching Ti In Progress and the record errors out. . 

I created this VR, tested it, and found not syntax errors. I was able to save the record even when the Resolution Type picklist was left blank. It should have prompted me to select a value from the picklist. 

Any help on this would be appreciated!
Thanks

 
1AND( 
2ISPICKVAL( StageName, 'Ti In Progress'), 
3RecordTypeId="0122E000000iFFKQA2", 
4ISBLANK(TEXT( Resolution_Type__c)) 
5)

 
Best Answer chosen by kjun
ApuroopApuroop
Try this.
 
AND( 
ISPICKVAL( StageName, 'Ti In Progress'),
RecordType.Name="NAME_OF_YOUR_RECORD_TYPE",
ISBLANK(TEXT( Resolution_Type__c))
)

All Answers

ApuroopApuroop
Try this.
 
AND( 
ISPICKVAL( StageName, 'Ti In Progress'),
RecordType.Name="NAME_OF_YOUR_RECORD_TYPE",
ISBLANK(TEXT( Resolution_Type__c))
)
This was selected as the best answer
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

Please try the below validation rule:
AND( 
    $RecordType.Id="0122E000000iFFKQA2", 
    ISPICKVAL( StageName, 'Ti In Progress'), 
    ISBLANK(TEXT( Resolution_Type__c)) 
)

Or you can use this:
AND( 
    $RecordType.Name = "Your Record Type Name", 
    ISPICKVAL( StageName, 'Ti In Progress'), 
    ISBLANK(TEXT( Resolution_Type__c)) 
)

Also, It's advisable to use the RecordType.DeveloperName so you can write the VR like this too:
AND( 
    $RecordType.DeveloperName = "Your_Record_Type_Name", 
    ISPICKVAL( StageName, 'Ti In Progress'), 
    ISBLANK(TEXT( Resolution_Type__c)) 
)

Please note that DeveloperName is not the same as Name. It is much like API names (can't start with a number, no spaces or punctuation, etc).
So, $RecordType.Name -> Record Type Label
and $RecordType.DeveloperName -> Record Type Name

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
kjunkjun
Thank you both! 
kjunkjun
I posted another VR ask if interested in figuring it out. 

Thank you!

https://developer.salesforce.com/forums/ForumsMain#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Formulas_Validation_Rules_Discussion&criteria=OPENQUESTIONS&id=9062I000000IKY2QAO 
Cory 16Cory 16
Why does RecordTypeId not work? I just ran into this same issue. RecordTypeId is a field on Opportunity that indeed has a value. Moreover, it is offered as a choice in the field selection menu in the validation rule creator screen. So why is Salesforce including RecordTypeId as an option if it's not actually supported in validation rules?? 
Ariel LegaultAriel Legault

Already solved, but wanted to add my two cents. I've found that the 15 digit id works in validation rules, just not the standard 18. So I delete the last 3 characters and it works just fine

Sample Validation Rule: each record type must have the correct kind of contract associated with it before it can be won

OR(
RecordTypeId = "0126g000000cnp5" &&
ISPICKVAL(StageName, "Won") &&
ISBLANK(ContractId) ,

RecordTypeId = "0126g000000iREA" &&
ISPICKVAL(StageName, "Won") &&
ISBLANK(ServiceAgreement__c)
)


So my edit would be 

AND(
ISPICKVAL(StageName, 'Ti In Progress'),
RecordTypeId="0122E000000iFFK",
ISBLANK(TEXT( Resolution_Type__c))
)