I am trying to query the child record using the parent record id. I understand that we have to use the child relation name in the inner query to get the child records.

select id, (select id from child_relationshipname__r ) from parentobjt__c

In my case I use the same way to query but I get the error :

ERROR at Row:1:Column:28
Didn't understand relationship 'cyx__r' in FROM part of query call. 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.

I am not sure why it is throwing error I doubled checked whether the child relationship name is correct.

select id, (select id from  namespc.Impacted_Products__r) from MC_Product_Complaint__c
  • 1
    Check the relationship name on the child object's lookup field, and also add the namespace if the object and field come from an installed managed package (e.g. namespace__relationshipname__r).
    – sfdcfox
    Apr 7 '17 at 20:56
  • yes it is from the installed package. May be that the issue. let me check
    – SfdcBat
    Apr 7 '17 at 20:59
  • I did add the name space but still get that error. attached some more details to question
    – SfdcBat
    Apr 7 '17 at 21:04
  • Is MC__Product_Complaint__c a valid name? I thought SF objects couldn't contain two underscores. Also, is the namespace actually namespace or did you blank out exact namespace?
    – Rob Davis
    Apr 7 '17 at 21:06
  • 1
    @SfdcBat It's namespace__relationshipname__r. No dots, just double underscores.
    – sfdcfox
    Apr 7 '17 at 21:08

The syntax for a child relationship is:


So if the relationship_name is Impacted_Products and the namespace is MC, your sub-query would be:

(SELECT Id FROM MC__Impacted_Products__r)

It looks like you used [namespace.] instead of [namespace__].

Note that you can always run this script to get the verbatim value you need to use in place of MC__Impacted_Products__r above:

for (ChildRelationship relation : SObjectType.Parent__c.getChildRelationships())
    if (relation.getChildSObject() == Child__c.sObjectType)
  • 1
    Thanks. Got it. Good to learn about the script to get verbatim value.
    – SfdcBat
    Apr 7 '17 at 21:11
  • Thank you for script! Mar 6 '19 at 10:28
  • does the script go up the relationship too? for parents? or is there a way for that? Mar 30 '20 at 21:04
  • 2
    @GibralterTop For a parent relationship name you would just do system.debug(Child__c.Parent__c.getDescribe().getRelationshipName() with no need for looping.
    – Adrian Larson
    Mar 31 '20 at 0:16

Where searching for the Child Relationship, you must use the Plural name of the Child Relationship object. For instance, if searching for the child Contacts on an Account it would be:

SELECT Id, ( SELECT Id FROM Contacts ) FROM Account;

In your specific case, try cyxs__r (I am assuming the plural of the cyx object is cyxs).


Not the answer you're looking for? Browse other questions tagged or ask your own question.