Addtional_Contact_Role__c has a lookup field to Contact. Why doesn't this Query work (what needs changing)? And can you explain why it is wrong? Where in eclipse can one see the correct relationship naming?

select ID,Email,(SELECT name from Additional_Contact_Role__r) FROM Contact
  • the relationship name usually be in plural... try Additional_Contact_Roles__r Jun 9 '16 at 9:12
  • The plural name is Positions (apparently the object was renamed). It didn't work.
    – Apex N-u-b
    Jun 9 '16 at 9:25
  • Did you tried with Plural Name which is there in Object Field Level?
    – Subhash
    Jun 9 '16 at 9:29
  • 1
    @ApexN-u-b go to Addtional_Contact_Role__c and go to contact lookup field and find relationship field name and append __r and then try. And if this is managed package part then just add namespace too. Jun 9 '16 at 10:03

If Addtional_Contact_Role__c has a lookup field to Contact, it means that Contact object is parent obj, Addtional_Contact_Role__c is child obj.

select ID,Email,(SELECT name from Additional_Contact_Role__r) FROM Contact

This query is calls child from mother obj. It supposed to be parent from child.

select Contact__r.Id, Contact__r.Email, Name from Additional_Contact_Role__r

Please check the link for more details about object relationships https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm


If the lookup to contact is on contact_role it may be easier to query the other way around.

SELECT ID,Name,Contact__r.Email FROM Additional_Contact_Role__c
  • I get this error : Didn't understand relationship 'Additional_Contact_Role__r' in field path.
    – Apex N-u-b
    Jun 9 '16 at 9:24
  • Hi Nielsm, This Query won't work because the Additional_Contact_Role has the Lookup to Contact and he is querying the Contact Object. So he wants to access the child records from parent
    – Subhash
    Jun 9 '16 at 9:30
  • I updated my response. Maybe more usefull if you tell some more about your use case. What do you need, what information do you have for filtering the query?
    – Nielsm
    Jun 9 '16 at 11:18

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.