You need to sign in to do that
Don't have an account?
Display lookup relationship in apex:pageTable
I have an custom object which has a lookup relationship to User (I call this field UserReference). I have a visualforce page that displays several fields for each object in an apex:pageTable.
How do I display the lookup relationship in this table? I don't want to display the user ID, I want to display the name.
I would like to do something like:
<apex:column > <apex:facet name="header">User namet</apex:facet> {!myObject.UserReference__c.Name} </apex:column>
but that clearly doesn't work.
I hope I don't have to loop through the list of myObjects in the controller and for each object perform a lookup into the user table to retrieve the name and then somehow make that available to the pageTable.
Anyone help me out?
Hi,
you have to use UserReference__r.Name instead of UserReference__c.Name see below code.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thanks,
Hitesh Patel
SFDC Certified Developer & Administrator
All Answers
Hi,
you have to use UserReference__r.Name instead of UserReference__c.Name see below code.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thanks,
Hitesh Patel
SFDC Certified Developer & Administrator
But that gives me an error:
Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: myObject.UserReference__r
I do include UserReference__c in my SELECT statement (in the controller) but I can't change this UserReference__r because that won't compile saying:
EDIT: I finally found a useful doc .. I added it as UserReference__r.Name in my SELECT and this works
Hi,
you have to add UserReference__r.Name in your SOQL query.
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thanks,
Hitesh Patel
SFDC Certified Developer & Administrator