You need to sign in to do that
Don't have an account?
eliotstock2
referring to children in a parent-to-child subquery
Hi.
I have a parent to child subquery like this:
for (Parent__c parent : [ SELECT Parent_Field__c, (SELECT Id, Child_Field__c FROM Childs__r WHERE Id IN :childIds) FROM Parent__c]) { // Do something with parent.Parent_Field__c }
If I have one parent with two children, I expect this to get me two records back. My question is, how do I then refer to the children of the parent? None of these seem to work:
parent.Childs__r.Child_Field__c parent.Childs__c.Child_Field__c parent.Child__r.Child_Field__c parent.Child__c.Child_Field__c
Thanks,
Eliot Stock.
Hey
Yeah it's a little different from child to parent. In your case you have to use a sort of Array syntax:
parent.childs__r[0].child_field__c
would access the first child.
Cheers,
Wes