I have a lookup field on case which points to case object. (Field: Parent__c). I want to query child case records from a parent case using an aggregate query. Below is the query I have used-

[SELECT Id, (SELECT Id,parent__c FROM Cases) FROM Case WHERE Id IN:SetIds ] 


However, this query is not returning anything in 'Cases' in spite of 'Child Relationship Name' for the field being 'Cases'. I know I am definitely missing something here. Hence request someone to please help me towards implementing my requirement.


The Cases relationship uses the built in ParentId field. Since you're using a custom lookup field, you need to use the custom relationship name, likely Cases__r.

  • First Go to the Case Object and then Open Your Parent__c field.

  • Now you got the Relationship Name here.

  • Then follow below Query :

    SELECT Id, (SELECT Id, parent__c FROM RelationshipName__r) FROM Case WHERE Id IN:SetIds

NOTE : If you are Using Custom Lookup Field for relationship Query, You must append the "__c" at the last of RelationshipName. And If you are using Standard Lookup Field for Relationship Query then there is no need to use "__r".

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.