Skip to Content

TheBlogReaders.com

Salesforce.com Learn & Share

How to find manager list using apex class in salesforce

Be First!
by February 24, 2018 APEX, SALESFORCE, Salesforce.com

How to find manager list using apex class in salesforce

Its possible to find out from managerId field in User Object and below is the code to find manager hierarchy for particular user.
set<Id> ManagerUserId=new set<Id>();
ManagerUserId.add(‘User id’);// Add user Id to whom you want to find manager list
getManagerId(‘LOGGED in User id’);// If you want to add base user also add this line else no need
system.debug(getManagerId);
public static void getParrentId(Id userId){
User userDetails = new User();
userDetails = [select Id, Name, ManagerId from User where Id =: userId];
if(userDetails.ManagerId != null){
ManagerUserId.add(userDetails.managerId);
getParrentId(userDetails.ManagerId);// Recursive call to find manager of manager
}
}

(3)

Previous
Next

Leave a Reply