5

I have a requirement where a certain field can be edited without the validations firing for a particular user. Now I tried to write rule like LastModifiedId != '005000000000000AAA' but the validation was still firing. Then I realized that until the record saves, the LastModifiedId does not change and the validations still fire, as the LastModifiedId would not be updated to the exempted User.

Is there any workaround or a way to check the Id of the User who is currently editing the record?

5
  • For example, you can use $User.id - success.salesforce.com/answers?id=90630000000h3IlAAI
    – kurunve
    Commented Mar 10, 2016 at 12:57
  • 3
    possible duplicate of allow user in validation rule Commented Mar 10, 2016 at 12:58
  • @TusharSharma Custom Permissions are a far preferable approach.
    – Adrian Larson
    Commented Mar 10, 2016 at 14:09
  • 2
    This does look like a duplicate question, but I'll vote to keep this open because the answer here is more comprehensive and up to date.
    – martin
    Commented Mar 10, 2016 at 14:29
  • Since the answer can be applied to merge fields anywhere, I edited the title to be more generally applicable (and hopefully more searchable).
    – Adrian Larson
    Commented Jul 14, 2016 at 20:57

1 Answer 1

8

There are a few approaches you can take here, which I will list in order of preference. These should work just about anywhere merge fields can be used.


Create a Custom Permission

You can check if someone has a Custom Permission in a formula as follows:

$Permission.My_Custom_Permission__c

Steps:

  1. Create Custom Permission
  2. Add it to a Permission Set
  3. Assign that Permission Set to any User you wish to exempt from validation

Hierarchy Custom Setting

If you don't find the above palatable for some reason, you can also check a Hierarchy Custom Setting in a formula as follows:

$My_Hierarchy_Setting__c.Is_Exempt_From_Validation_X__c

Steps:

  1. Create Hierarchy Custom Setting
  2. Add exemption field
  3. Set Org Wide Default for this field to false
  4. Set value to true for any User you wish to exempt from validation

Alias

You can check against an Alias in a way that in all environments as follows:

$User.Alias = "analias"

Username

Somewhat less clean than Alias, but you would check against a Username as follows:

BEGINS($User.Username, "[email protected]")

User Id

I would not adopt this approach unless you have compelling reasons none of the above are a good fit:

$User.Id = "00550000000lxVg"
8
  • 2
    I've also used $User.alias to avoid the BEGINS (your third option)
    – cropredy
    Commented Mar 10, 2016 at 20:34
  • @crop1645 Ah very nice alternative. Will amend my answer.
    – Adrian Larson
    Commented Mar 10, 2016 at 20:34
  • 1
    @AdrianLarson detail solution. +1 Commented Mar 11, 2016 at 4:56
  • Used the $User.alias method. Worked like a charm, thank you! :)
    – User2529
    Commented Mar 11, 2016 at 4:58
  • Can also use a custom field on user. No real advantages vs the other methods, but it's an option...
    – gorav
    Commented Aug 13, 2016 at 17:07

You must log in to answer this question.

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