I'm trying to get the values from sub query result using java code and partner connection, but I'm not able to get the inner records.
I tried using XmlObject. I'm able to use below code in parse the XmlObject and retrieve the relevant data. Still want to know if there is more simple way.
QueryResult queryResult = connection.query("SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account LIMIT 10");
for(SObject acc : queryResult.getRecords()){
Sytem.out.println("account name: " + acc.getField("Name"));
XmlObject childsRecords = (XmlObject) acc.getChild("Contacts");
//Need loop over Contact records
Iterator<XmlObject> innerChild = childsRecords.getChildren();
while(innerChild.hasNext()){
XmlObject contactXml = innerChild.next();
System.out.println("Contact Id: " + contactXml.getField("Id"));
}
}
attachments.getChildren()
? Where did you define theattachments
variable? That code is very unclear.acc.getChild("Contacts")
should return aList<sObject>
(or java equivalent).