Lead Change owner restricted to users based on a Role - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
parth Patelparth Patel 

Lead Change owner restricted to users based on a Role

Hi There,

I have a following role structure

Managing Director
 - Business Unit 1
 - Business Unit 2

User Salesforce1 belongs to Busines Unit 1

User Salesforce2 belongs to Busines Unit 2

Lead Object is set to OWD Private
Sharing rules are setup to read write for Roles and subordinates.
 

A lead created by a user in role Business Unit 1 is not Visible to Business Unit 2 user.

All of the above works fine.

The issue is Change Owner at the lead record allows me to assign to any user which is not in the same role.

Though it gives me an error in the screen for secruity it ends up in assigning a lead to a user in different business unit.

How can i restrict the Change Owner button to allow only the users in Same Business unit and not another. up in the hierarchy its fine if it displays all users.

Please advise.

Best Answer chosen by parth Patel
Amit SinghAmit Singh
Try below validation Rule to show the Error if the user is not in the same Role 
IF(
   AND(
       $UserRole.Name <> 'Business Unit2',
       ISCHANGED(OwnerId),
       Owner:User.UserRole.Name ='Business Unit2'
   ),
   true,
   IF(

   AND(
       $UserRole.Name <> 'Business Unit1',
       ISCHANGED(OwnerId),
       Owner:User.UserRole.Name ='Business Unit1'
   ),
   true,
   false

   )
   
)

Regards,
Amit

All Answers

Vish NagarajuVish Nagaraju
Lookup filters with filter crietria is the best candidate too restrict lookup users based on record or user criteria.
Below link would help you understand more about this.
https://help.salesforce.com/articleView?id=fields_lookup_filters.htm&type=5

Thanks,
 Vish
Amit SinghAmit Singh
Try below validation Rule to show the Error if the user is not in the same Role 
IF(
   AND(
       $UserRole.Name <> 'Business Unit2',
       ISCHANGED(OwnerId),
       Owner:User.UserRole.Name ='Business Unit2'
   ),
   true,
   IF(

   AND(
       $UserRole.Name <> 'Business Unit1',
       ISCHANGED(OwnerId),
       Owner:User.UserRole.Name ='Business Unit1'
   ),
   true,
   false

   )
   
)

Regards,
Amit
This was selected as the best answer
Amit SinghAmit Singh
@ Vish,

We can only use the Lookup filters for custom lookup fields we can not modify the Standard fields
Vish NagarajuVish Nagaraju
@Amit :-) Thanks. Completely missed to think that it was a standard field.
parth Patelparth Patel
Awesome @amit that worked a treat.
Vish thanks for your input.
Amit SinghAmit Singh
@vish, No issue sometimes it happens.

@Parth, glad to help you. You owe me a beer hahaha  just kidding 
Cheers :)
parth Patelparth Patel
@Amit sure for that you need to come to Sydney!! :)