0

I have a Salesforce Parent child relationship. I need to get parent and child records from a Heroku app. Following is the SOQL. However partner stub does not have a way to get child records? Anyone knows how to do this?

SELECT id, (select id,cxsrec__Job_requirements_text__c,cxsrec__Job_description_text__c from cxsrec__Job_profile_translations__r)  FROM cxsrec__cxsFunction__c where id = 'XXXX'
0

I debugged and found a way to do this. Find the sample code.

    public void test(){

    try {
        PartnerConnection connection = Connector.newConnection(config);
        QueryResult qResult = null;
        String soqlQuery = "SELECT id, (select id,cxsrec__Job_requirements_text__c,cxsrec__Job_description_text__c from cxsrec__Job_profile_translations__r)  FROM cxsrec__cxsFunction__c where id = 'XXXXXXXXXXXXXXXXX'";      
        qResult = connection.query(soqlQuery);          
        SObject [] sObjects = qResult.getRecords();
        for (SObject sObj:sObjects) {
            XmlObject obj =  sObj.getChild("cxsrec__Job_profile_translations__r");
            Iterator<XmlObject>iChild = obj.getChildren();
            while (iChild.hasNext()) {
                Object obj1 = iChild.next();
                if (obj1 instanceof SObject) {
                    SObject objs = (SObject)obj1;
                    System.out.println(objs.getId());
                    System.out.println(objs.getField("cxsrec__Job_requirements_text__c"));
                    System.out.println(objs.getField("cxsrec__Job_description_text__c"));
                }
            }               


        }

    } catch (ConnectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
| improve this answer | |

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.