3

I have 2 custom objects

  1. addressMaster
  2. addressDetail - has foreign key field which is linked with the id field of the master.

Here is SOQL I tried:

SELECT Id, Name, sumchans__totalUnits__c, (SELECT sumchans__aaUnits__c,sumchans__lastReportDate__c,sumchans__nnUnits__c,sumchans__addressForeignKey__r  FROM addressDetails) FROM sumchans__addressMaster__c where id='a014600000C7DNlA3N'];

enter image description here

5

As with any subquery, you have to use the correct relationship name. It is quite trivial to find via a script such as:

for (ChildRelationship relation : SObjectType.MyObject__c.getChildRelationships())
    if (relation.getSObject() == Child__c.sObjectType)
        system.debug(relation.getRelationshipName());

The debug statement should give you exactly the name of the relationship you should use in the join. Likely instead of sumchans__addressDetail__c, it is sumchans__addressDetails__r. Note that it is plural and ends in __r, not __c.

  • Sorry Adrian, just was confused with the code, wondering would you be able to use my code above as an example an mark the places where changes are required. – Sumchans Jan 10 at 23:39
  • The error message itself tells you exactly what you need to fix... – Adrian Larson Jan 11 at 0:13
  • I have the made some changes to original post. I used the plural name of the child object in the inner soql. Still I get an error. – Sumchans Jan 11 at 0:20
  • I was able to make it work finally – Sumchans Jan 11 at 0:48
  • thanks for highlighting the plural vs. singular detail. made a massive difference – Andre de Miranda Mar 29 at 6:16

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.