+ 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