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
Stephen Chin 5Stephen Chin 5 

Display value from related lookup record in Visualforce page

I created a custom object called Usage that has a lookup relationship to the standard Account object. I am trying to create a Visualforce page that will display all of the fields from a Usage record directly on the Account page if the two are linked via the lookup field.

I am new to VF, and I created a VF page with the following code:
<apex:page standardController="Account">

<apex:pageBlock title="Usage">
    <apex:pageBlockSection>
        <apex:outputField value="{! Account.Usage__c.Name }"/>
        <apex:outputField value="{! Account.Usage__c.Last_User_Login_Date__c }"/>
        <apex:outputField value="{! Account.Usage__c.Request_Manager_Enabled__c }"/>
        <apex:outputField value="{! Account.Usage__c.Users__c }"/>
    </apex:pageBlockSection>
</apex:pageBlock>
    
</apex:page>
However, I get the following error when trying to save: Could not resolve the entity from value binding '{Account.Usage__c.Name}' can only be used with SObjects, or objects that are Visualforce field component resolvable.

I looked into SObjects but am unclear what the issue is.
 
ShirishaShirisha (Salesforce Developers) 
Hi Stephen,

Greetings!

If you would like to display the related Objects data on the parent Object then you should call the child Object as Usage__r(customObjects).If it is standard Objet then this should be Usages.

So,please try by changing the extension from __c to __r and let me know,if it fix the issue.

Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Mohammed MohiddinMohammed Mohiddin
Since Usage is a related list of Account, there will be many usage records under that account. so you need to display usages in a loop.
Here is an example
 
<apex:page standardController="Account">

<apex:pageBlock title="Usage">
    <apex:pageBlockSection>
      <apex:repeat value="{!Account.Usage__r}" var="usage" >
        <apex:outputField value="{! usage.Name }"/>
        <apex:outputField value="{! usage.Last_User_Login_Date__c }"/>
        <apex:outputField value="{! usage.Request_Manager_Enabled__c }"/>
        <apex:outputField value="{! usage.Users__c }"/>
      </apex:repeat>
    </apex:pageBlockSection>
</apex:pageBlock>
    
</apex:page>

Just try this and let me know if you need further assistance