+ Start a Discussion
Team WorksTeam Works 

Display the people who report to logged in user?

Hello friends,

I need to create a visual force page where i need to display me and people who report to logged in User(me)....ofcourse based on the role hierarchy setup in my Org.

Kindly guide me to link explaining such an example or how can i approach this?

Many Thanks

Best Answer chosen by Team Works
Vinit_KumarVinit_Kumar
Try below code :-

List<Id> uRoleIds= new List<Id>();

// Query User role object to get all the Roles under Logged in User's role
List<UserRole> urole = [select id from UserRole where ParentRoleId=:UserInfo.getUseRoleId()];

//Populating the list to get all User Role Ids
for(UserRole u : urole)
{
	uroleIds.add(u.id);
}

Query on User object to get the related Users
List<User> userList = [select id,username from User where UserRoleId in:uroleIds];

If this helps,please mark it as best answer to help others.

All Answers

Vinit_KumarVinit_Kumar
Query on User object and filter on ManagerId,I mean query on all the Users for whom the Manager is Logged in User.So,your query should be something like below :-

// Query on User based on ManagerId

List<User> userList = [select id,username from User where ManagerId=:UserInfo.getUserId()];

And,now you can display the List in a pageblocktable on VF page.

If this helps,please mark it as best answer to help others.
Team WorksTeam Works
Hi Vinit,

Thanks for your reply. Cannot we do something like this. Find the RoleId of the logged in User. Then find the roleIds ID for the roles under this Role and find the users with this role RoleId ID? If yes, need help on the fields to relate.

Many Thanks
Vinit_KumarVinit_Kumar
Try below code :-

List<Id> uRoleIds= new List<Id>();

// Query User role object to get all the Roles under Logged in User's role
List<UserRole> urole = [select id from UserRole where ParentRoleId=:UserInfo.getUseRoleId()];

//Populating the list to get all User Role Ids
for(UserRole u : urole)
{
	uroleIds.add(u.id);
}

Query on User object to get the related Users
List<User> userList = [select id,username from User where UserRoleId in:uroleIds];

If this helps,please mark it as best answer to help others.
This was selected as the best answer
Team WorksTeam Works
Thanks for the clues...I was able to do it.