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

output list from a SOQL sub-query

Hi there,
I'm trying to list all direct reports for the logged in User using User and UserRole.
I'm querying the UserRole tables ParentRoleID field to find any children of the parent, then going back to the User table to find the users login id.
Here is my controller:
public class FindReports {

public List<UserRole> getMyRoles() {
    //return [Select u.UserRole.Name, u.UserRole.Id, u.UserRoleId, u.Alias From User u WHERE u.UserRoleId != null LIMIT 10];
 return [Select u.Name, u.Id, (SELECT Alias FROM Users) From UserRole u WHERE u.ParentRoleId = :UserInfo.getUserRoleId()];



I can't seem to access the "Alias" from the Users object in my VisualForce code:
<apex:page Controller="FindReports" tabStyle="Account">
 <apex:pageBlock title="My Reports Roles">
 <apex:dataTable value="{!myRoles}" var="aRole" cellpadding="2" rowClasses="odd,even" styleClass="tableClass">
     <apex:column >
      <apex:facet name="header"><b>Role Name</b></apex:facet>

     <apex:column >
      <apex:facet name="header"><b>Role ID</b></apex:facet>
 <apex:column >
      <apex:facet name="header"><b>User 6+2</b></apex:facet>
      <!--  {!aRole.Users.Alias}  -->

 I can't find "Alias" in the returned Object: java.util.ArrayList does not have the property "Alias".
Thank you!

Hi Jill,

I actually read that thread 3 times before I posted, but I do want the entire list of names.

Is it a matter of moving the object name (aRole) from the page to the controller?

If you want the list then you'll have to use another iterating component to iterate over the list.  So something like
<apex:repeat value="{!aRole.users}" var="aliasUser">

Any time you're trying to access a list of objects you need to drop into one of our components that supports iteration (dataTable, pageBlockTable, repeat).
Will this work for lookup relationships?