[SalesForce] Validation rules Account: Changing owner limitation

I am trying to create a validation rule for Account. I want to limit the capability of the user to transfer the accounts (or changing de ownerID of the Account) . I only want them to be able to transfer Accounts to users that have the same role.

I am not being able to create the validation rule, this is sample of what I did but it is not working.

AND(
   ISCHANGED( OwnerId ),
   VLOOKUP($User.UserRole.name,$User.Id,PRIORVALUE(OwnerID)) = $UserRole.name
)

Thanks in advance for any tips.

Best Answer

You could create a formula field on the object that holds the Owner.UserRole.Name then use that in your validation rule like:

AND(
   ISCHANGED(OwnerId),
   PRIORVALUE(Owner_Role__c) <> Owner.UserRole.Name
)  

Which would only allow users to change the owner if the existing owner has the same Role as the new owner.

Related Topic