function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris ParisChris Paris 

Validation Rule to prevent transfer records outside of role

I have a requirement to create a validation rule to prevent transferring of records outside of a role.  I would like to allow users of a role to transfer objects owned by users in their role.  Any users outside of their role would not have permission to transfer records.  

Currently, our security is set to private and we enable view access to all accounts,leads,opportunity objects.  We have in place sharing rules per object per role, that give access to users within their respective role to edit those objects.  People outside that immediate role, do not have access to edit those objects.

The solution provides this : 

Mary in Role A
Joe in Role A
Bob in Role B

Mary can transfer an account that Joe owns into her name, but cannot transfer an account that Bob owns.  Bob cannot transfer Mary or Joe's account into his name.  

Is there a formula to use for a validation rule to only allow transferring objects based on roles as described in the example above?

Thanks!
Best Answer chosen by Chris Paris
Romeo Ngo 1Romeo Ngo 1
It should be a simple trigger.  Make sure you allow some users to override this trigger so you don't get into a situation that manager/higher-up/admin can't assigned from a user in Role A to a user in Role B.  Let me know if you need anymore help.

All Answers

Romeo Ngo 1Romeo Ngo 1
If the transfer user is always the account owner then you can easily accomplish this.  

Noticed the formular below is checking on the current users and not the Account owner.  So if the manager of that user (RoleA) (who belong in another role) want to transfer to another user in RoleA then he/she may get an error.  In that case you may want to improve your formula to ignore when users in specific roles are making the changes.
AND(
     !ISNEW() ,
     ISCHANGED(OwnerId),
     $User.UserRoleId  != Owner.UserRoleId
)


There is a long and correct way for manager case above if you want to even only allow the managers to transfer account to user with the same Role as the current account owner.  




 
Chris ParisChris Paris
Hi Romeo,

That validation rule still allows Mary in Role A to transfer Bob's account (in Role B) into Mary's name.  
Once that account is in Mary's name, she can transfer to Joe but cannot transfer out of her role.  

How do we add in the clause - do not allow Mary to transfer Bob's accounts into her own name? 

Thanks
Romeo Ngo 1Romeo Ngo 1
Ah my bad, I didn't see you are allowing all users to take account ownership instead of having the current account owner transfering the account to another user.

In this case, then you may have to use a trigger to accomplish this.  Validation has an option to get the PreviousValue but for related object. IE, it only get the previous ID of the related objec, in this case previous owner ID.  However, we can't get the Previous Owner RoleID with validation formula.

So the short answer is we can't use Validation rule to accomplish this unless we use a trigger to update a custom field of the previous owner Role and use that field in your validation rule.  Or to save you a validation rule to manage, simple throw the error within the trigger when previous user Role != current user role.

Hope this helps.
Chris ParisChris Paris
Thanks Romeo! I thought that was the case but wanted to make sure. 
In terms of building out this trigger, would it b a complex trigger or somethig a developer could write in a few hours?  Just trying to understand the scope a little better

thank you again! 
Romeo Ngo 1Romeo Ngo 1
It should be a simple trigger.  Make sure you allow some users to override this trigger so you don't get into a situation that manager/higher-up/admin can't assigned from a user in Role A to a user in Role B.  Let me know if you need anymore help.
This was selected as the best answer