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
SF_Gh0stSF_Gh0st 

Add field from another object

Hi,

I have a visualforce page that is mainly related to the account object in the sense that all the fields on the page are from the account object. However there is one field on a custom object (address) that I want to add to this VF page. What is the best way to do that? I thought I could add a lookup field from account to address (address__c is the lookup field) but that doesnt seem to work, I tried something like this:
<apex:outPutText value="{!acct.address__r.customField__c"/>
Is it possible to do something like this or do I need to do anything to the controller? Thanks.
 
Suraj Tripathi 47Suraj Tripathi 47

Hi,

You can take references from the below code.

<apex:page controller="forAccount">
 
    <apex:form >
        
         <apex:pageBlock title="List Of Contact">
            <apex:pageBlockTable value="{!contactList}" var="con">
                <apex:column value="{!con.LastName}"/>
                 <apex:column value="{!con.Account.Name}"/>
            </apex:pageBlockTable>
            
        </apex:pageBlock>

    </apex:form>
    
    
</apex:page>
 
public class forAccount {
 
    
    public List<Contact> contactList{
        get;
        set;
    }
     public  forAccount(){
        
          contactList=[select LastName,Account.Name from Contact where accountid!=null limit 100];
     }
 
}


Please mark it as the Best Answer if it helps you

Thank You

SF_Gh0stSF_Gh0st
Hi, I have added the class to the accountHandler and I add the code below to the VF page, but I only see the 'status' field.  I don't see anything else under it or above it and I don't get any error. I just added those text values to determine if I could see anything at all, but I can not.
<apex:pageblock>
                 <apex:pageBlockTable value="{!contactList}" var="con">  
                               <apex:outputText value="The unformatted time right now is: {! NOW() }" />
                               <apex:facet name="header">Status</apex:facet>
                               <apex:outputtext value="{!con.getAdd__c}"/>
                               <apex:outputText value="The unformatted time right now is: {! NOW() }" />
                  </apex:pageBlockTable>
</apex:pageblock>