+ Start a Discussion
Charline MitchenerCharline Mitchener 

Display values from a secondary account linked to contact in visualforce page

I have create a visualforce page, using apex that looks up and displays a number of fields from the contact object as well as the account linked to that contact. 

A number of contacts have a 'secondary account', which they are linked to. There is a custom field on the contact layout named secondary_account__c, which is an account lookup field. 

I need to display fields from both accounts within the visualforce page, i.e. the Address from both Accounts within the one visualforce page. How would I detail this within the apex code I have created? If I just have , account.billingcity for example, how would I add it, and differentiate it from the first account, to show the billing city for the second account?

Prabhat Kumar12Prabhat Kumar12
I believe you are using standard controller on you Visualforce Page. 

If you want to display secondary account name then you can do like this.
<apex:outputText value = "Contact.secondary_account__r.BillingCity"/>

Charline MitchenerCharline Mitchener
Hi, thank you for your reply. I have added those fields to the apex controller and the visualforce page as per above, but the values are not displaying in the VF page on preview?

Added the fields to the apex controller, which I presume are correct as I didn't receive an error message


And added the code to the VF page -
<apex:outputText value="{!contact.Secondary_account__r.Entity_Name__c}" />
<apex:outputText value="{!contact.Secondary_account__r.Company_AR_Number__c}" />