0

I have tested the following query which is successful but when apply the query to my custom object it fails. i need to find out what is causing the issue.

SELECT Id, Account.Name FROM Contacts WHERE AccountId in (SELECT Id FROM Account)

Background: There are two entities: Customers and Visits, there can be many visits for any customer. I have created a custom object Customer_Visits__c with several fields. It has a lookup field called Customer__c which looks up to Account (sObject) and stores the Account Id field. The relationship name is CustomerVisitsAccounts. I want to be able to return the customer name field (Account.Name) in the SOQL query, i.e., for each visit record show the name of the customer. It get success with:

SELECT Id, Name FROM Customer_Visits_c WHERE Customer_c in (SELECT Id FROM Account)

Here is the SOQL string I get fails with:

SELECT Id, Name, CustomerVisitsAccounts__r.Name FROM Customer_Visits_c WHERE Customer_c in (SELECT Id FROM Account)

Here is the error message I get:

ERROR at Row:1:Column:18 Didn't understand relationship 'CustomerVisitsAccounts_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.

Bartley
  • 290
  • 2
  • 7
  • 21
  • 1
    Are you *sure* that's the name of the relationship? Try viewing your data model with the Workbench: https://workbench.developerforce.com/login.php. – amrcn_werewolf Sep 20 '13 at 16:14
  • Thanks for that, I ran it through WorkBench and got the following error: 'Parent relationship queries are disabled in Workbench: CustomerVistsAccounts__r.Name' So to clarify, the parent object holds the fields that I want to query through the child object. Workbench shows the relationship through the parent, i.e., 'customer' and the relationship name is 'customerVistsAccounts__r' and the field I want to query is called 'name' Do you know why this would cause a problem? – Bartley Sep 20 '13 at 20:14
  • When you say workbench shows the relationship through the parent, are you saying that there's a field there called "customer" (or "customer__c") and when you open that field in Workbench you see relationshipName: customerVisitsAccounts__r? Or is there maybe another relationship in between here? – amrcn_werewolf Sep 21 '13 at 03:45

0 Answers0