+ Start a Discussion
RuslanRuslan 

Unable to get records of a related object

I have a custom object Deal__c and a standard object Contact.  The I created a custom lookup field Contact in the Deal__c object (related to Contact object).  Then I went to Deal__c page layout and added Contact to Selected Relationship Fields.
 
At this point I would like to display all contacts that are related to a particular Deal.
 
<apex:page standardController="Deal__c">
   <apex:pageBlock title="Hello {!$User.FirstName}!">
      You are viewing the {!Deal__c.name} deal.
   </apex:pageBlock>
   <apex:pageBlock title="Contacts">
      <apex:pageBlockTable value="{!Deal__c.Contact}" var="contact">
         <apex:column value="{!contact.Name}"/>
         <apex:column value="{!contact.MailingCity}"/>
         <apex:column value="{!contact.Phone}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>
 
As a result I get an error message: 
Error: Invalid field Contact for SObject Deal__c
 
If I change {!Deal__c.Contact} to {!Deal__c.Contact__c} then I get a different error message: 
Error: Unknown property 'String.Name'
 
Where am I going wrong here?
 
Appreciate any suggestions
 
Best Answer chosen by Admin (Salesforce Developers) 
DevGarethmdDevGarethmd
Use the relationship Contact__r. So your value should be "{!Deal__c.Contact__r}"

All Answers

DevGarethmdDevGarethmd
Use the relationship Contact__r. So your value should be "{!Deal__c.Contact__r}"
This was selected as the best answer
RuslanRuslan
Great.  Thanks.  I used Contact__r and I am no longer geting an error.  The Contact block is displaying fine but I don't see any contacts within it.  This deal that I have up when testing this has two contacts associated with it.  Any idea why they are not coming up?
 
Thanks again