In situations like the one that you're facing, I find it can be helpful to try to manually step through a process to try to understand what's going on.
I'm assuming that your user id isn't the one being restricted. For ease, let's pretend that your validation rule is currently this:
OR(
ISCHANGED(OwnerId),
ISCHANGED(Name),
ISCHANGED(RecordTypeId),
AND($User.Id= '005000000000123')
)
and that your user id is 005000000000789
So, why is this validation rule preventing you from editing fields?
Say you've edited the record's name, and only the name. Let's step through the validation rule.
ISCHANGED(OwnerId)
, this statement is false
, since we're only changing the name
ISCHANGED(Name)
, this statement is true
ISCHANGED(RecordTypeId)
, this statement is false
$User.Id = '005000000000123'
, since your user id is 005000000000789
, this statement is false
Now that we've evaluated part of the statement, we can substitute statements for their values. In the eyes of Salesforce, your validation rule now looks like this1:
OR(
false,
true,
false,
AND(false)
)
AND()
-ing a single term produces the same value as the term itself, so, simplifying a little bit, we get
OR(
false,
true,
false,
false
)
If any single condition in an OR()
is true, the result is true. If a validation rule's formula ends up evaluating to true (as it does in the case when you, yourself, edit the Name
field), then the validation rule steps in, displays its error message, and prevents the record change from happening.
Now that we know what went wrong, how do we make it work?
The short answer is, unsatisfyingly, you don't. Validation rules are meant to prevent people from putting a record into a state where some piece of data is bad.
Validation rules aren't the right tool to use to restrict access to fields. They can be used in very simple cases (i.e. prevent this user from editing this specific field). If the problem that you're trying to solve is "prevent x from editing any fields except fields x, y, z", then validation rules are of little help.
Instead of a validation rule, the tool I'd suggest using is profiles.
You can create a custom profile for this user, and give the profile permissions to create, read, and modify all Account
records. After that, you can edit the Field-Level Security of the fields that you don't want this user to be able to edit to remove the edit
permission for that one user profile (or more than one profile, if you're so inclined).
1: This isn't technically 100% true. Through my own testing that I did in writing one of my first answers on this site, Salesforce evaluates validation rules in a lazy fashion. That is, if we can get the result of a statement by only evaluating part of it, Salesforce will only do as much work as they need to to get the answer. In this particular case, the evaluation stops after evaluating ISCHANGED(Name)
. This is because, in boolean logic, inside an OR()
, the whole thing will result in true
once we find the first thing that evaluates to true
. In reality, ISCHANGED(RecordTypeId)
and AND($User.Id =
'value')
aren't evaluated, because doing so would not change the result. The overall OR()
function would still return true
.