Monday 22 May 2017

How to avoid hard coded record type id from Validation rule ?

Hi All,

It is not best pratice to use hard coded id value in validation rule or in any formula field logic, because ID value will keep on changing form environment to environment.

if we use hard coded id then it will cause lot of maintenance activity. Here is an example where hard code Id value is being used and how to achieve without using hard code value.


AND( ISBLANK(CustomField__c ), 
RecordTypeId ='0124B0000004aZ4', 

OR(ISPICKVAL(Type, 'New'), 
ISPICKVAL(Type, 'Reserved')), 
NOT($Profile.Name ='Integration Admin'))

Instead of recordtypeid it is better to use Recordtype.developername.

AND( ISBLANK(CustomField__c), 
RecordType.DeveloperName ='Marketing_Event', 
OR(ISPICKVAL(Type, 'New'), 
ISPICKVAL(Type, 'Reserved')), 
NOT($Profile.Name ='Integration Admin'))