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
Vijayakumar KenchugunduVijayakumar Kenchugundu 

RecordTypeId in Validation Rule is not firing

Friends,
I have written a validation rule on Account object to stop saving if Account record type id is of certain type. I know it is advisable to use RecordTypeId instead of RecordType.Name. Here is my validation rule formule:
IF( RecordTypeId = "0122i000000613oAAA",
true,
false)

It is not stopping Saving the record if the recordtypeid is 0122i000000613oAAA. It is very strange. Any thoughts to overcome this are highly appreciable.
Best Answer chosen by Vijayakumar Kenchugundu
ravi soniravi soni
Hy VijayKumar,
as per your requirment that Why Validation is not work at recordType
find your solution from below info.
Actual RecordTypeId is eighteen(18) characters but in validation rule when we use RecordTypeId that time it only generate fiften(15) charctor that's why our validation not work but if you want to use validation rule then you have to take 15 letter Id like below.
Actual RecordTypeId => 0125g000000p3wnAAA with 18 letters but i'd only 15 letter.
IF( RecordTypeId = '0125g000000p3wn',
true,
false)

I think above info will be enough for understanding.
let me know if it helps you and don't forget to mark it as best answer.
Thank you

All Answers

Pranali Dhoke 25Pranali Dhoke 25
Hi Vijaykumar,

You can use RecordType.DeveloperName instead of RecordTypeId.

Thanks,
Pranali
Vijayakumar KenchugunduVijayakumar Kenchugundu
Hi Pranali,

If I use .DeveloperName, if we change the name later in future to different name, then the validation rule will fail. Can you please confirm the DeveloperName is never going to change though the RecordType.Name is changed?
ravi soniravi soni
Hi,
try following trigger for this requirment.
trigger restrictRecordbasedOnRecordType on Opportunity (before insert,before update) {
    if(trigger.isBefore && (trigger.isInsert || trigger.isUpdate)){
        for(Opportunity Opp : trigger.new){
            if(Opp.RecordTypeId == '0125g000000p3wnAAA'){
                Opp.addError('user Can not change Record for this recordTypeId');
                
            }
            
        }
    }

}
we have to use trigger for this requirment because your can  even change developerName.so use trigger and close your query by marking it as best answer.
let me know if it helps you and marking it as best answer.
Thank you
 
Vijayakumar KenchugunduVijayakumar Kenchugundu
Hey Veer,
Your trigger should work. But I would like to know why can't I use the below. Any thoughts?
IF( RecordTypeId = "0122i000000613oAAA",
true,
false)
AbhinavAbhinav (Salesforce Developers) 
Hi VijayaKumar,

Please check below link which has explanation  for use case

Instead of hardcoding the id's you can use RecordType.DeveloperName = "API name of record type" or RecordType.Name = "Label name of record type". If you still want to use Recordid try using "RecordType.Id"

reference:
https://salesforce.stackexchange.com/questions/311112/validation-rule-to-prevent-creating-records-of-certain-record-type-not-working

If it helps mark it as best answer.

Thanks!
ravi soniravi soni
Hy VijayKumar,
as per your requirment that Why Validation is not work at recordType
find your solution from below info.
Actual RecordTypeId is eighteen(18) characters but in validation rule when we use RecordTypeId that time it only generate fiften(15) charctor that's why our validation not work but if you want to use validation rule then you have to take 15 letter Id like below.
Actual RecordTypeId => 0125g000000p3wnAAA with 18 letters but i'd only 15 letter.
IF( RecordTypeId = '0125g000000p3wn',
true,
false)

I think above info will be enough for understanding.
let me know if it helps you and don't forget to mark it as best answer.
Thank you
This was selected as the best answer
Vijayakumar KenchugunduVijayakumar Kenchugundu
Finally, 
The resolution for my question is: Use 15 letter Id worked. And RecordType.Id did not work.
Thanks everyone for your thoughts. Much appreciated.