1

SELECT parent_object__c.Name, (SELECT Child_object__r.Name FROM Child_object__c ) FROM parent_object__c WHERE parent_object__c.Id IN (SELECT child_object_c.Id FROM child_object__c)

I am trying to create an inner join as per this example

https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html

SELECT Account.Name, (SELECT Contact.Name FROM contacts) FROM Account WHERE Account.Id IN (SELECT Contact.accountId FROM Contact)

Can anyone advise what I am doing wrong, please

1 Answer 1

0

You will need to use the right child Relationship Name in your query.

Try the below

SELECT parent_object__c.Name, (SELECT Child_object__c.Name FROM Child_objects__r ) FROM parent_object__c WHERE parent_object__c.Id IN (SELECT parent_object__r.Id FROM child_object__c)

The above assumes Child_objects is your child relationship Name.

For your use case, the below should work if you have the right childrelationship Name

SELECT Name, (SELECT Id FROM enrtcr__Funded_Support_Contract_Clients__r) FROM enrtcr__Support_Contract__c WHERE Id IN (SELECT Id FROM enrtcr__Funded_Support_Contract_Client__c)

7
  • 1
    Usually the child relationship name is plural.
    – Adrian Larson
    Commented Apr 28, 2021 at 0:26
  • Ah good point!! Commented Apr 28, 2021 at 0:27
  • Are you saying it should read child_objects__r. instead of child_object__r I thought purals was just for friendly name rather than API name ?
    – Jack Nolan
    Commented Apr 28, 2021 at 0:38
  • 1
    It depends on what is your child relationship Name. To find it search for the parent reference field on the child object and note its child relationship name. check here developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/… Commented Apr 28, 2021 at 0:40
  • No look guys even when I try using childs__r. SELECT enrtcr__Support_Contract__c.Name, (SELECT enrtcr__Funded_Support_Contract_Client__c.Id FROM enrtcr__Funded_Support_Contract_Clients__r) FROM enrtcr__Support_Contract__c WHERE enrtcr__Support_Contract__c.Id IN (SELECT enrtcr__Funded_Support_Contract_Client__r.Id FROM enrtcr__Funded_Support_Contract_Client__c).
    – Jack Nolan
    Commented Apr 28, 2021 at 0:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .