2

I have a custom object, Session, with 4 similar lookup fields that all look up to contacts. The fields are:

  • Teacher__c
  • Teacher2__c
  • Tutor1__c
  • Tutor2__c

In the Query Editor, the following SOQL query works fine:

Select Id, Name, Teacher__r.Name From Cluster__c

Replacing Teacher__r with Teacher2__r gets the following error:

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

The same happens for Tutor1__r and Tutor2__r. I'm baffled. Is there some rule against having more than one lookup to the same kind of object? Is there some special syntax that needs to be used in such a case?

  • 3
    Asking the obvious here but Cluster__c and Session are the same object? – greenstork Oct 22 '14 at 21:18
  • Multiple references to the same object do work; double check the "API Name" using e.g. Setup -> Create -> Objects -> Session__c/Cluster__c. – Keith C Oct 22 '14 at 21:22
  • 1
    Cluster and session are related (cluster used as a template for session). The problem here is that in the dim prehistory of these objects, the naming was not done consistently. I was looking at the names in session, but the query, of course, was on cluster. @greenstork, if you'll make that comment an answer, I'll happily accept it. – Jagular Oct 22 '14 at 21:27
1

Your query is looking at the Cluster object, which doesn't appear to have those fields, that is the problem. Your lookup fields are on Session so the relationships that you want to traverse, and the query, need to be on the Session object.

| improve this answer | |
  • The names are subtly different between the objects. Bad practice and the parties responsible have been sacked. – Jagular Oct 22 '14 at 21:39

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.