0

My validation rule

AND(
       $Profile.Name <> "System Administrator",
       $User.Id <> "0053600000xxxxxxxx",
       NOT(ISNEW()),
NOT(CONTAINS("Kristen Becker:Lisa Wilt", Permission_To_CSM__c ))
)

The validation rule need to satisfy the below conditions

  • Only works on edit mode.
  • The System Administrator can do anything with the record.
  • User with Id==>0053600000xxxxxxxx can do anything with the record as like admin.
  • When Lookup relational field Permission_To_CSM__c has value only "Kristen Becker" or "Lisa Wilt" then the user can edit the record.

Why my validation rule can not satisfy the above requirements. Help me to fix the validation rule.

enter image description here

User Fields in validation rule.

User>>Name filed missing in validation rule

Validation rule error

enter image description here

1 Answer 1

1

If Permission_To_CSM__c is a lookup field then if you refer it as Permission_To_CSM__c in your validation rule or apex code it will give you 15 or 18 character salesforce record id. You can get Name or any other field of your lookup object by simply changing __c to __r and then . with API name of the field.

As the lookup is to user object so name field will not be available for use in validation rule or formula field. You can build the name directly in the validation rule by concatenating the first name and last name or you can create a formula field for name on the user object or account object (whichever one you prefer) and refer to that in your validation rule.

For example, I have created a formula field Name_Formula__c on the user object.

enter image description here

If you want to get the Name_Formula__c field then you can get it like this Permission_To_CSM__r.Name_Formula__c

Your validation rule will look something like this.

AND(
       $Profile.Name <> "System Administrator",
       $User.Id <> "0053600000xxxxxxxx",
       NOT(ISNEW()),
       NOT(
               OR(
                      CONTAINS("Kristen Becker", Permission_To_CSM__r.Name_Formula__c),
                      CONTAINS("Lisa Wilt", Permission_To_CSM__r.Name_Formula__c)
               )
       )
)
5
  • field name does not exist (Permission_To_CSM__r.Name) reason is validation rule>> inser field option has no field named (Name). Permission_To_CSM__r.Name works perfectly on SOQL but not work on validation rule.
    – shamim
    Commented Jul 5, 2021 at 2:44
  • Could you please post exact error message you are getting on referencing Name field
    – Elijah
    Commented Jul 5, 2021 at 4:27
  • @elijah, please check my question context, the error is 'Error: Field Name does not exist. Check spelling.'
    – shamim
    Commented Jul 5, 2021 at 9:53
  • Yes, Name field of the user object is not available in the formula and in the validation rules. What you can do is you can create a formula field on the user object "Name_Formula" of data type text and build name with first name and last name. And you can refer this in your validation rule. Commented Jul 5, 2021 at 15:07
  • @shamim I have edited my answer please have a look. Commented Jul 5, 2021 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .