+ Start a Discussion
Vipin K 10Vipin K 10 

SOQL for Lead/Roles

Hi All,

I want to write an query to find lead visibliity based on roles. We have sharing settings enabled but for some reasons i am not able to get leads based on roles . Can some one help me with the query.

Need Lead Name, Status, Owner, User Role
Best Answer chosen by Vipin K 10
LBKLBK
Does this help you?
 
SELECT Id, Name, Status,  Owner.Name, Owner.UserRole.Name FROM Lead
Let me know.
 

All Answers

LBKLBK
Does this help you?
 
SELECT Id, Name, Status,  Owner.Name, Owner.UserRole.Name FROM Lead
Let me know.
 
This was selected as the best answer
Vipin K 10Vipin K 10
Hi guys , thanks a lot that helped. How do we query the role hierarcy?

 
LBKLBK
I don't think you can retrieve the entire hierarchy in a single SOQL.

Following query can provide you the Parent Role of the current Owner's Role.
 
SELECT Id, Name, Status,  Owner.Name, Owner.UserRole.Name, Owner.UserRole.ParentRoleId FROM Lead
But, you may need some custom APEX code to establish the hierarchy.