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.