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
NIyathiNIyathi 

Find the SubRoles for the Role Id and the users under each Sub Role for the entered Role Id on page

Hello, 
I have a requirement like this.
Create a Visualforce page:
Enter Role Id: [Input Field]
"Go" button
User enters a RoleId, and clicks on Go button. This will display the Sub Ordinate role Ids under the Role Id that was entered in the page. And the Users that are under each SubOrdinate Role.

Roles:
       RoleId1
               UserId1
               UserId2
       RoleId2
               UserId1
               UserId2
       RoleId3
               UserId1
               UserId2
Please helpme on this.

Thanks,
Niyathi
 
Michał Zadrużyński 2Michał Zadrużyński 2
If you just want to get 1 level below typed role
List<UserRole> childRoles = [select id from UserRole where ParentRoleId = :typedRole];
so you have all child roles, now to get users:
List<User> users = [select id, ..., UserRoleId from User where UserRoleId in :childRoles];
now simple make map UserRoleId->User and you have all you need. But if you want all sub roles tree then you need to go with DSF alghoritm using those selects