+ 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"/>



Thanks.
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

 Secondary_account__r.BillingCity,
                   Secondary_account__r.billingstreet,
                   Secondary_account__r.billingstate,
                   Secondary_account__r.billingpostalcode,
                   Secondary_account__r.billingcountry,
                   Secondary_account__r.Trading_Name_ABN_Number__c,
                   Secondary_account__r.Trading_Name__c,
                   Secondary_Account__r.Entity_Name__c,
                   Secondary_account__r.Company_AR_Number__c,

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