function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AkiTAkiT 

Query a list of subordinate (child) roles for user

Hi,

Anyone done this before, any tips?

I'd like to create a list of subordinate roles for a user that is running my s-control. This would be used to populate a selection list with all user's subordinates.

-Aki
Best Answer chosen by Admin (Salesforce Developers) 
WhyserWhyser

It depends on how far you want to go wtih the "subordinates".

If you are going one level deep.. you can retrieve them with

Select u.FirstName, u.Id, u.LastName, u.UserRoleId, u.UserRole.Name from User u Where u.UserRole.ParentRoleId = '{!$User.UserRoleId}'

If you need to go deeper, you're going to have to write some code to iterate over the result set that would take the "u.UserRoleId" field and re-run the query above with the {!$User.UserRoleId} replaced with your "UserRoleId" field from the result set.