Created
October 17, 2022 17:24
-
-
Save emoran/910f5936d6c2d1da85801177000cb5e7 to your computer and use it in GitHub Desktop.
get Top Manager in Salesforce Apex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public Employee__c getTopManager(String employeeId){ | |
Boolean topLevel = false; | |
Employee__c top_employee = new Employee__c(); | |
while(!topLevel){ | |
Employee__c employee = [Select Id,Name,Manager__c from Employee__c where Id =:employeeId limit 1]; | |
if(employee.Manager__c != null){ | |
employeeId = employee.Manager__c; | |
} | |
else{ | |
top_employee = employee; | |
topLevel = true; | |
System.debug('Manager: '+top_employee); | |
} | |
} | |
return top_employee; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment