Validation Rule to Restrict Lookup by Specific Profiles - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
J CJ C 

Validation Rule to Restrict Lookup by Specific Profiles

Using Lightning - I am trying to create a VR that restricts entry of a new User into a custom Lookup field (Project Manager) if the User selected has a specific Profile (Platform).

I have tried a couple of different options but neither work. I can still add a User with the a Platform Profile into the Project Manager field.

Attempt #1
$Profile.Id = "XXXXXXXXXXXXXXX"

Attempt #2
pse__Project_Manager__r.pse__Salesforce_User__r.ProfileId = "XXXXXXXXXXXXXXX"

Thank you in advance for your help and consideration :)

Best Answer chosen by J C
Jayson MoralesJayson Morales
Hi JC,

Click Insert Field then Object name then Project Manager> then Profile> then Name.

The formula should look something like this:
AND(
pse__Project_Manager__r.Profile.Name = "Profile Name",
ISCHANGED(Project_Manager__c)
)

Hope that helps.

Regards,
Jayson

All Answers

Moustafa IshakMoustafa Ishak
What do you mean by new User ? is it new record ?
J CJ C
@Moustafa, Great question. It is not a new user record. It's when the field is updated changing the current value (user) to a different value (user). I'm happy to answer any additional questions you may have :)
Moustafa IshakMoustafa Ishak
Could you try this one 
($Profile.Name == 'Specific Profile', ISCHANGED(Project_Manager__c))

please change the values for 'Specific Profile' & Project_Manager__c
J CJ C

@Moustafa, Thank you. I tried the above and I am receiving a syntax error.

 Error: Syntax error. Missing ')'

I tried adding more to the closing but still receiving this error. I also updated the code to the following, still the same error.

($Profile.Name == "PSE - Time Entry (Platform User)",
    ISCHANGED(Project_Manager__c))

Moustafa IshakMoustafa Ishak
And($Profile.Name == "PSE - Time Entry (Platform User)",  ISCHANGED(Project_Manager__c))
J CJ C
Closer! The Formula passed syntax validation but did not pass testing. I was still able to add a User with the Platform Profile into the PM field.
Moustafa IshakMoustafa Ishak

And($Profile.Name == "PSE - Time Entry (Platform User)",  OR(ISCHANGED(Project_Manager__c),ISNEW(Project_Manager__c)))
J CJ C

@Moustafa, thank you for all your help. I received a syntax error on this formula.

Error: Incorrect number of parameters for function 'ISNEW()'. Expected 0, received 1

Jayson MoralesJayson Morales
Hi JC,

Click Insert Field then Object name then Project Manager> then Profile> then Name.

The formula should look something like this:
AND(
pse__Project_Manager__r.Profile.Name = "Profile Name",
ISCHANGED(Project_Manager__c)
)

Hope that helps.

Regards,
Jayson
This was selected as the best answer
J CJ C

@Jayson, Thank you so very much!! I changed the formula just slightly. I was receiving a syntax error on the Profile Name otherwise.

AND(
pse__Project_Manager__r.pse__Salesforce_User__r.Profile.Name = "PSE - Time Entry (Platform User)",
ISCHANGED(pse__Project_Manager__c)
)

Thank you for all your help!! Hope everyone has a wonderful evening!