I have created a custom lookup field on the User object. This lookup field is of the User type and the idea is that each User would have a manager assigned to them.

Custom Lookup field details

Field Label FOO Manager

Field Name FOO_Manager

API Name FOO_Manager__c

Data Type Hierarchy

Object Name User

Child Relationship Name FOO_Managers

I created a VF page as follows:

<apex:page standardController="User">
    <apex:pageBlock title="Foo Title">
        <b>Foo Manager <i>{!$User.FirstName}</i></b>

    <apex:relatedList list="FOO_Managers" title="Related FOOs"/>

Unfortunately, on the page I am getting a blank page. I am not sure what I am doing wrong here. According to this link from the VisualForce docs regarding related lists, the list attribute should contain the following:

The related list to display. This does not need to be on an object's page layout. To specify this value, use the name of the child relationship to the related object. For example, to display the Contacts related list that would normally display on an account detail page, use list="Contacts".

What am I not understanding here?

-- EDIT --

According to the first answer, the above is not possible. An alternative has been proposed as follows:

<apex:page standardController="User">
    <apex:pageBlock title="Foo Title">
        <b>Manager <i>{!$User.FirstName}</i></b>

        <apex:pageBlockTable value="{!User.FOO_Managers__r}" var="u">
            <apex:column value="{!u.Name}" />

Data has been ensured to be correct, where the $User is the FOO Manager of User u (and u would have its FOO Manager lookup field populated by $User). It seems however that I am getting a blank result as shown below.

enter image description here

It seems that an entry is being listed, but no data can be seen. Is it possible that viewing permission issues can affect the view here?


The problem is solved by specifying the ID of the current user in the page URL. Indeed, this can (and ideally will) also be achieved programatically.

For example: /apex/MyVFPage?Id=ID_OF_MANAGER

  • There is a standard field on the User object called Manager. Why didn't you use that? – DavidSchach Jan 10 '18 at 17:22
  • It's being used for something else already. – edgaralienfoe Jan 10 '18 at 18:02
  • 1
    You forgot to include the Id of the User in the URL (see my answer below) – Bob Lopez Jan 10 '18 at 21:45

The User object does not support Related Lists, so this is not possible using apex:relatedList.

As a side note, when you are using apex:relatedList with Custom Relationships, you need to include __r in the relationship name. So your example should be:

<apex:relatedList list="FOO_Managers__r" title="Related FOOs"/>

To answer your question on how to display a table of related Users, you can create your own Related List using apex:pageBlockTable.


<apex:page standardController="User">
    <apex:pageBlock title="Foo Title">
        <b>Foo Manager <i>{!User.FirstName}</i></b>

    <apex:pageBlock >
        <apex:pageBlockTable value="{!User.FOO_Managers__r}" var="u">
        <apex:column value="{!u.FirstName}" />
        <apex:column value="{!u.LastName}" />

Visiting the page, you must include the Id of the User (Manager) which you want to see the subordinates (related users). ex: /apex/MyVFPage?Id=ID_OF_MANAGER

enter image description here

  • Just like a Contact would contain a lookup field for the Account, my User would contain a lookup field known as FOO Manager that points to another User. Now, with that in mind, I want to present a list of FOOs for a particular FOO Manager, just like one would present a list of Contacts for a particular Account. – edgaralienfoe Jan 10 '18 at 17:15
  • I see. So how can I present such a list in this case instead of using a related list? – edgaralienfoe Jan 10 '18 at 17:15
  • you can create your own related list table (see my edited post) – Bob Lopez Jan 10 '18 at 17:21
  • So {!User.FOO_Managers__r} is the relationship between a User (FOO Manager) and the User's FOOs? I thought the __r reference only applies for custom objects. The FOO_Manager lookup points to a User object not a custom object. I am confused because I specified the Child Relationship Name for the lookup as FOO_Managers. – edgaralienfoe Jan 10 '18 at 18:19
  • In this case, FOO_Managers__r isn't a Custom Object, it is a Custom Relationship Field. Sorry for the confusion, in my answer I should have said "Custom Relationship" instead of "Custom Object" – Bob Lopez Jan 10 '18 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.