You need to sign in to do that
Don't have an account?
geeljire
Traversing lookup fields to related record fields
I'm trying to access a contact object field through a related object's lookup field. Billing_contact__c below (2nd <td>) is an entity object lookup field that has a related contact record. When I reference the Address__c field in the contact object, I get the following error:
Error: Unknown property 'String.Address__c'
Any idea why? And how can I accomplish my goal of displaying this contact object field?
<apex:repeat value="{!entities}" var="r"> <tr> <td>{!r.Name}</td> <td>{!r.Billing_Contact__c.Address__c}</td> <td>{!r.Email_1__c}</td> <td>{!r.Phone_1__c}</td> <td><apex:outputfield value="{!r.Inactive__c}"></apex:outputfield></td> <td>{!r.CreatedBy.Name}</td> </tr> </apex:repeat>
If address is your custom field on your contact object you have to made following change
<td>{!r.Billing_Contact__r.Address__c}</td>
Or if you are trying to access standard fields than you have to write code with following way
<td>{!r.Billing_Contact__r.MailingStreet}</td>
<td>{!r.Billing_Contact__r.MailingCity}</td>
<td>{!r.Billing_Contact__r.MailingState}</td>
<td>{!r.Billing_Contact__r.MailingCountry}</td>
<td>{!r.Billing_Contact__r.MailingPostalCode}</td>
<td>{!r.Billing_Contact__r.MailingStateCode}</td>
<td>{!r.Billing_Contact__r.MailingCountryCode}</td>
for other addrss field also you have to write this way. all Mailling Word will be replaced with Other.
If your data is coming from controller you to include these field name in your Query.
like :
[Select Billing_Contact__r.MailingStreet, Billing_Contact__r.MailingCity, .......... From Entiry]
All Answers
If address is your custom field on your contact object you have to made following change
<td>{!r.Billing_Contact__r.Address__c}</td>
Or if you are trying to access standard fields than you have to write code with following way
<td>{!r.Billing_Contact__r.MailingStreet}</td>
<td>{!r.Billing_Contact__r.MailingCity}</td>
<td>{!r.Billing_Contact__r.MailingState}</td>
<td>{!r.Billing_Contact__r.MailingCountry}</td>
<td>{!r.Billing_Contact__r.MailingPostalCode}</td>
<td>{!r.Billing_Contact__r.MailingStateCode}</td>
<td>{!r.Billing_Contact__r.MailingCountryCode}</td>
for other addrss field also you have to write this way. all Mailling Word will be replaced with Other.
If your data is coming from controller you to include these field name in your Query.
like :
[Select Billing_Contact__r.MailingStreet, Billing_Contact__r.MailingCity, .......... From Entiry]
Try following changes. For more details refer this link.
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
Hit the Kudos button if any post helps you - Mark the answer as solution, It might help others running to into similar problem in future.
Thank you Shiv and Chamil. Both of your answers are very helpful indeed. If I could choose both as solutions, I would.