You need to sign in to do that
Don't have an account?
To Query the Parent child values in SOAP API using Enterprise WSDl
Hi Everyone
I want to query the parent child relation how can i do it,
Can please some one share the idea and the code is below.
Please suggest what i was missing.
package com.sforce.soap.classes;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.sforce.soap.enterprise.LoginResult;
import com.sforce.soap.enterprise.QueryResponse;
import com.sforce.soap.enterprise.QueryResult;
import com.sforce.soap.enterprise.SessionHeader;
import com.sforce.soap.enterprise.SforceServiceLocator;
import com.sforce.soap.enterprise.SoapBindingStub;
import com.sforce.soap.enterprise.fault.LoginFault;
import com.sforce.soap.enterprise.fault.UnexpectedErrorFault;
import com.sforce.soap.enterprise.sobject.Account;
import com.sforce.soap.enterprise.sobject.Contact;
import com.sforce.soap.enterprise.sobject.SObject;
public class ParentchildRelation {
static ParentchildRelation _childQuery;
public static void main(String[] args) {
// TODO Auto-generated method stub
_childQuery=new ParentchildRelation();
try{
_childQuery.childQuery(null);
}catch (Exception e) {
// TODO: handle excebinption
e.printStackTrace();
}
}
public SObject childQuery(QueryResult qrP2C2) throws UnexpectedErrorFault, LoginFault,
RemoteException
{
SoapBindingStub binding;
try {
binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
LoginResult _lr=binding.login("madhu3006@gmail.com", "Ni@$3006VrI8LOopmy4E8NIk7kn4ioMx");
String seessionid=_lr.getSessionId();
System.out.println("Seesion ID"+seessionid);
binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, _lr.getServerUrl());
SessionHeader sh=new SessionHeader();
sh.setSessionId(_lr.getSessionId());
System.out.println();
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),"SessionHeader",sh);
//String query1="SELECT Name,(SELECT firstname,lastname from Contacts) from Account";
QueryResult qrP2C = binding.queryMore("SELECT Name,(SELECT firstname,lastname from Contacts) from Account LIMIT 1");
//SObject SoResult=qrP2C.getRecords()[0];
//QueryResult subqr=(QueryResult)(((Object) SoResult).get_any()[0].getObjectValue());
//QueryResult subQR = (QueryResult)(SoResult.get_any()[0].getObjectValue());
//QueryResult subQR = (QueryResult)(SoResult.getClass().g);
//String na
//binding.queryAll(query1);
//QueryResult subr=SoResult.getClass().getName();
ParentchildRelation _acct1= new ParentchildRelation();
SObject test= _acct1.childQuery(qrP2C);
String name=test.getClass().getName();
System.out.println("Test Name"+name);
// System.out.println("Account Name is "+acctname);
Contact _cont=new Contact();
String fname=_cont.getFirstName();
System.out.println("Contact FirstName is "+fname);
String lname=_cont.getLastName();
System.out.println("Contact LastName is "+lname);
binding.clearHeaders();
binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(),"SessionHeader", sh);
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
Regards
Madhu