+ Start a Discussion
MJ09MJ09 

Validation rule for a lookup field's RecordType.Name

I'd like to create a validation rule that ensures that if a lookup field in my custom object is non-null, it refers to a record with a particular record type. I know how to write that validation rule using RecordTypeId:

 

    myfield__r.RecordTypeId = "012800000006Rz1"

 

But the custom object containing this rule will eventually be packaged into an App Exchange offering, so I can't rely on the Id always being the same. How can I write this rule to check the field's RecordType.Name?

 

I've tried the following, but I get "Field RecordType does not exist"

 

    myfield__r.RecordType.Name = "My RecordType Name"

 

Any ideas?

 

Best Answer chosen by Admin (Salesforce Developers) 
TLFTLF

This is an old thread, but I was trying to do this and found a solution that doesn't require a hard-coded RecordType ID:

 

 

AND($RecordType.Name="SpecialCampaign", ISBLANK(CampaignID__c))

This fires the validation rule if the Campaign.RecordType.Name = "SpecialCampaign" and the custom CampaignID field is blank. This is packageable, since it's not using a hard-coded ID.

 

All Answers

werewolfwerewolf
Hm.  Well that's an interesting one.  I tried it too and had the same problem.  I think you might be SOL on the validation rule -- you may have to do it with a before * Apex trigger.
TLFTLF

This is an old thread, but I was trying to do this and found a solution that doesn't require a hard-coded RecordType ID:

 

 

AND($RecordType.Name="SpecialCampaign", ISBLANK(CampaignID__c))

This fires the validation rule if the Campaign.RecordType.Name = "SpecialCampaign" and the custom CampaignID field is blank. This is packageable, since it's not using a hard-coded ID.

 

This was selected as the best answer
MJ09MJ09

TLF,

 

Way to update an old thread with a good answer! Thank you!

 

MJ.