I am trying to connect to other salesforce org.
I have partner wsdl. I have used FuseIT SFDC explorer to create Apex class from this partner wsdl.
I am successfully able to login to other SF org using login() call.
But my query() call is failing with error –
Web service callout failed: Unable to parse callout response. Apex type not found for element MyCustomField__c
Looks like this has to do with sObject_x class created by FuseIT SFDC explorer.
Below is the code which makes query() call,
partnerSoapSforceCom.Soap partnerObj = new partnerSoapSforceCom.Soap(); //login here and login is successful partnerSoapSforceCom.QueryResult qresult = partnerObj.query('select Id, MyCustomField__c from MyCustomObject__c'); system.debug('resule size - ' + qresult.size );
Below is QueryResult class created by the tool,
public class QueryResult { public Boolean done; public String queryLocator; public sobjectPartnerSoapSforceCom.sObject_x[] records; public Integer size; private String[] done_type_info = new String[]{'done','urn:partner.soap.sforce.com','boolean','1','1','false'}; private String[] queryLocator_type_info = new String[]{'queryLocator','urn:partner.soap.sforce.com','QueryLocator','1','1','true'}; private String[] records_type_info = new String[]{'records','urn:partner.soap.sforce.com','sObject','0','-1','true'}; private String[] size_type_info = new String[]{'size','urn:partner.soap.sforce.com','int','1','1','false'}; private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'}; private String[] field_order_type_info = new String[]{'done','queryLocator','records','size'}; }
Below is the sObject_x class created by the tool,
public class sobjectPartnerSoapSforceCom { //Warning: '<xsd:any>' element type has been changed to dataType List<DOM.XmlNode> called anyElement public class sObject_x { public String type_x; public String[] fieldsToNull; public String Id; public List<DOM.XmlNode> anyElement; private String[] type_x_type_info = new String[]{'type','urn:sobject.partner.soap.sforce.com','string','1','1','false'}; private String[] fieldsToNull_type_info = new String[]{'fieldsToNull','urn:sobject.partner.soap.sforce.com','string','0','-1','true'}; private String[] Id_type_info = new String[]{'Id','urn:sobject.partner.soap.sforce.com','ID','1','1','true'}; private String[] anyElement_type_info = new String[]{'anyElement','urn:sobject.partner.soap.sforce.com','List<DOM.XmlNode>','0','1','true'}; private String[] apex_schema_type_info = new String[]{'urn:sobject.partner.soap.sforce.com','true','false'}; private String[] field_order_type_info = new String[]{'type_x','fieldsToNull','Id','anyElement'}; } }
any idea what is causing this error ?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The trick here is in the warning message that is included in the sobjectPartnerSoapSforceCom class:
//Warning: ‘<xsd:any>’ element type has been changed to dataType List<DOM.XmlNode> called anyElement
Natively WebServiceCallout.invoke
can’t handle the <xsd:any>
that appears in the WSDL for sObjects. See Supported WSDL Features.
I’ve tried to work around it by using a List of DOM.XmlNodes to represent the arbitrary elements, but there isn’t an easy way to name the native web service methods convert the SOAP response.
However, all is not lost. The FuseIT version of WSDL2Apex can also generate the required HttpRequest to invoke the web service and process the response.
When selecting the methods to generate for, you can use the “Select Method Type” drop down to indicate that you also want the HttpRequest to be generated. This will take more lines of Apex code, but gives you more options to invoke the method.
This will generate an alternative query method with the _http
suffix.
public partnerSoapSforceCom.QueryResult query_Http(String queryString) { DOM.Document doc = new DOM.Document(); DOM.XmlNode body = populateDoc(doc); DOM.XmlNode methodNode = body.addChildElement('query', 'urn:partner.soap.sforce.com', ''); partnerSoapSforceCom.query_element request_x = new partnerSoapSforceCom.query_element(queryString); request_x.populateXmlNode(methodNode); // .... }
Using this method you can run the SOQL query and get the resulting sObject.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0