+ Start a Discussion
RovRov 

Validation rule to conditionally make a lookup field required

I have a field called IT Executive Team of data type lookup on users. 

 

I want to create a validation rule to make it a required field for all users who are not in a particular role.

 

Any pointers will be greatly appreciated. Thanks in advance

 

 

Best Answer chosen by Admin (Salesforce Developers) 
RovRov

Worked out the solution -

 

IF(
    AND(
               NOT CONTAINS($UserRole.Name ,"IT Management"),
               ISBLANK(IT_Executive_Team__c)
            ),
true,
false
)


All Answers

SFDC-cloudSFDC-cloud

You can add a Validation rule to it;

 

eg:

 

ISBLANK( lookupfieldname__c )

 

I tired it just now to make sure this works and it did work.

 

RovRov

ISBLANK( lookupfieldname__c ) makes it required for all users.

I want to make it required only for some users. 

E.g The lookup field can be blank if a $UserRole.Name = 'Manager' Else Required field.

RovRov

Worked out the solution -

 

IF(
    AND(
               NOT CONTAINS($UserRole.Name ,"IT Management"),
               ISBLANK(IT_Executive_Team__c)
            ),
true,
false
)


This was selected as the best answer
Shashikant SharmaShashikant Sharma
AND(ISBLANK(LookupFieldAPIName) , OR( $UserRole.Name = 'CEO' , $UserRole.Name = 'CFO'))

 

try this , please add your lookup field api name and role names in Or condition , you can write as many in role separating with ,

 

RovRov

Thanks Shashikant!! This is how I did, it worked. Please advise if you think this is not a viable option.

 

IF(
    AND(
               NOT CONTAINS($UserRole.Name ,"IT Management"),
               ISBLANK(IT_Executive_Team__c)
            ),
true,
false
)

Shashikant SharmaShashikant Sharma

I would suggest you to change it to this

 

AND(ISBLANK(LookupFieldAPIName) , $UserRole.Name <> 'IT Management')

 Why i used <> ( this means Not equals to) instead of Contains is that if any some new Role comes like this in future 

IT Management Company or IT Management Reporting they will also by pass your validation. Even though it is kind of thinking for future scenario. Up to you now.

 

 

 

RovRov

Thanks heaps!! Much appreciated.