0

I have Custom object DriverEfficiency__c which has (contact(lookup),Car_Meter_Reading__c,Efficiency_Rating__c,Fuel_Liter__c) fields.

The Problem is I need to create a Vf Page to retrieve records from contact and DriverEfficiency__c..

I used Wrapper Class to retrieve records from different objects.But I got the unrelated result.Contact field displays unrelated records for DriverEfficiency__c.

I need related contact records for the DriverEfficiency__c.(which has contact lookup)

  • is ur requirement to show all the contacts and its linked driver efficiency records ? or only for a certain set of contacts ? – Vamsi Krishna Mar 25 '15 at 5:49
  • Yes.My requirement to show all the contacts and its linked driver efficiency records in Vf page.I am getting unlinked contacts from the above code.I need exact contacts linked with driver efficiency..Please help me... – Sandra Mar 25 '15 at 6:24
1

enter image description hereYou can try solving your problem using relationship queries.

http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_relationships.htm

For now you can try this query

[select Car_Meter_Reading__c,Efficiency_Rating__c,Fuel_Liter__c, Contact__r.name,Contact__r.Phone from DriverEfficiency__c  ]
  • I tried this code in Developer Console it shows following error. Efficiency_Rating__c,Fuel_Liter__c, Contact.name,Contact.Phone from ^ ERROR at Row:1:Column:65 Didn't understand relationship 'Contact' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. – Sandra Mar 25 '15 at 6:26
  • sorry my bad.. append __r after contact, i have edited the query you can try this code now – Maruf Bagwan Mar 25 '15 at 8:58
  • Sorry.It is showing same error.....Didn't understand relationship 'Contact__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. – Sandra Mar 25 '15 at 9:03
  • Here "Contact__r" represent your Relationship name. Go to your DriverEfficiency object fields -> Open Lookup(contact) type field ----> In that scroll down and see "Relationship Name" --------- You need to use that name by concatinating "__r" . for exmaple : Relationship name = DriverContact ----> then use ---- DriverContact__r.Phone, DriverContact__r.Name – Salesforce Steps Mar 27 '15 at 13:10
-2
  1. Go to your custom object, then go to the lookup field.

  2. Select 'Field Name' value (Assume you have 'Contact_ABC'). Note : Do not use API Name or relationship name.

  3. suffix __r to it. That will give you relationship name and you can use it to query any field Example : Contact_ABC__r.id - This will give you contact ID Contact_ABC__r.name - This will give you contact Name

  • 1
    This approach will not always work. For example, if there is a namespace. – Adrian Larson Jul 31 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.