You need to sign in to do that
Don't have an account?

Get Same Role and Subordinate Users
This methods are used for Get Same Role and Subordinate Users.
public static Set<ID> getSameRoleSubordinateUsers()
{
Set<ID> userIds = new Set<ID>();
// get current user's role id
Map<Id,User> users = new Map<Id, User>([Select Id, Name From User where UserRoleId=:userinfo.getuserroleid()]);
userIds.addAll(users.keySet());
// get all of the roles underneath the user
Set<Id> allSubRoleIds = getAllSubRoleIds(new Set<ID>{userinfo.getuserroleid()});
// get all of the ids for the users in those roles
Map<Id,User> subUsers = new Map<Id, User>([Select Id, Name From User where
UserRoleId IN :allSubRoleIds]);
userIds.addAll(Subusers.keySet());
// return the ids as a set so you can do what you want with them
return userIds;
}
private static Set<ID> getAllSubRoleIds(Set<ID> roleIds)
{
Set<ID> currentRoleIds = new Set<ID>();
// get all of the roles underneath the passed roles
for(UserRole userRole :[select Id from UserRole where ParentRoleId IN :roleIds AND ParentRoleID != null])
currentRoleIds.add(userRole.Id);
// go fetch some more rolls!
if(currentRoleIds.size() > 0)
currentRoleIds.addAll(getAllSubRoleIds(currentRoleIds));
return currentRoleIds;
}
Thank's
Ramakrishnan Ayyanar
+919944112175
public static Set<ID> getSameRoleSubordinateUsers()
{
Set<ID> userIds = new Set<ID>();
// get current user's role id
Map<Id,User> users = new Map<Id, User>([Select Id, Name From User where UserRoleId=:userinfo.getuserroleid()]);
userIds.addAll(users.keySet());
// get all of the roles underneath the user
Set<Id> allSubRoleIds = getAllSubRoleIds(new Set<ID>{userinfo.getuserroleid()});
// get all of the ids for the users in those roles
Map<Id,User> subUsers = new Map<Id, User>([Select Id, Name From User where
UserRoleId IN :allSubRoleIds]);
userIds.addAll(Subusers.keySet());
// return the ids as a set so you can do what you want with them
return userIds;
}
private static Set<ID> getAllSubRoleIds(Set<ID> roleIds)
{
Set<ID> currentRoleIds = new Set<ID>();
// get all of the roles underneath the passed roles
for(UserRole userRole :[select Id from UserRole where ParentRoleId IN :roleIds AND ParentRoleID != null])
currentRoleIds.add(userRole.Id);
// go fetch some more rolls!
if(currentRoleIds.size() > 0)
currentRoleIds.addAll(getAllSubRoleIds(currentRoleIds));
return currentRoleIds;
}
Thank's
Ramakrishnan Ayyanar
+919944112175
try below code.....
Users subordinates:https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yq5IAA
Thanks,
Rockzz
It's correctly work.
You just view the code.How to simplify this.