I need to write a validation rule based on the recordTypeId. I would like to make sure that when the users selects a record via a lookup field the rule will check if the record chosen is of a specific RecordType.
How can I use the $RecordTypeId or $RecordTypeName in the validation rule formula to achieve this?
Attribution to: Dedo
Possible Suggestion/Solution #1
We started the practice of putting a custom field on any object that we would use a record type for called "Record Type Name".
It's a formula field that has value $RecordType.Name
This lets you refer to record types by name in Apex without having to do an extra query, but it may also keep things simpler for validation rules.
Attribution to: Shane McLaughlin
Possible Suggestion/Solution #2
You can do this in two ways.
- Use a filtered lookup if there are additional criteria on the (base) record that you would like to base the validation on.
- Use the record type name/Id of the record being looked up (using relationships like Customer__r.RecordTypeId)
Attribution to: Oxene
Possible Suggestion/Solution #3
Under Validation Rules you just setup a simple comparison to the Record Type name. An example using Leads would be:
RecordTypeId = 'Record Type Name'
For a custom object it might be something like:
$RecordType.DeveloperName = "Record Type name"
Attribution to: Mike Chale
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4856