1

I'm trying to set up a validation rule where only the current record owner or an administrator can change the account ownership. This is what I have at the moment:

AND(
     ISCHANGED(OwnerId),
     $User.Id <> PRIORVALUE(OwnerId),
     $Profile.Name <> 'System Administrator'
)

This validation works for my above case. Now I would like to expand this validation rule to also let certain user_ids to change account ownership regardless of them being an owner. I've tried changing it to:

AND(
     ISCHANGED(OwnerId),
     $User.Id <> PRIORVALUE(OwnerId),
     $Profile.Name <> 'System Administrator',
     $User.Id = "Specific user id"
)

But adding this allows all users to change the account owner.

1 Answer 1

1

Consider using Custom Permissions instead of hardcoding ids in the validation rule. Hardcoding ids is always not the best practice. Let's say, that you'll want to have this validation rule working on a sandbox. With hardcoded ids, it will not work as expected.

1. Create Custom Permission called Change Owner with API name Change_Owner.

2. Edit validation rule as following:

AND(
    ISCHANGED(OwnerId),
    $User.Id <> PRIORVALUE(OwnerId),
    NOT($Permission.Change_Owner)
)

3. Assign Change_Owner custom permission to System Administrator profile.

4. Create a new Permission Set and add Change_Owner custom permission to this Permission Set.

5. Assign newly created permission set to users, which should be allowed to change an OwnerId field.


Following this approach, you'll have flexibility in assigning permission to skip this validation rule without editing metadata, and which is more important, this functionality will work properly on any sandbox.

1
  • 2
    Excellent solution Oleksandr!
    – ECallpani
    Nov 10, 2021 at 12:05

You must log in to answer this question.

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