1

I am trying to fetch the account records from the queryResult of Salesforce to Salesforce integration response. But unable to split from the data. Can someone please help me.

string query1 = 'Select Id, Name, phone from Account limit 10';
partnerSoapSforceCom.QueryResult qr = new partnerSoapSforceCom.QueryResult();
qr =  partner.Query_http(query1);
List<sobjectPartnerSoapSforceCom.sObject_x> sobjectlist =  qr.records;
for(sobjectPartnerSoapSforceCom.sObject_x aa : sobjectlist ){
system.debug('aa.type_x---'+aa.type_x);
system.debug('aa.fieldsToNull---'+aa.fieldsToNull); 
system.debug('aa.anyElement---'+aa.anyElement); 
}

Here the output response from the above debug log is like below...

(sObject_x:[Id=0013I000003wus6QAA, Id_type_info=(Id, urn:sobject.partner.soap.sforce.com, ID, 1, 1, true), anyElement=(XMLNode[ELEMENT,Id,urn:sobject.partner.soap.sforce.com,null,null,[XMLNode[TEXT,null,null,null,null,null,0013I000003wus6QAA,]],null,], XMLNode[ELEMENT,Name,urn:sobject.partner.soap.sforce.com,null,null,[XMLNode[TEXT,null,null,null,null,null,test Account,]],null,], XMLNode[ELEMENT,Phone,urn:sobject.partner.soap.sforce.com,[common.apex.api.dom.XmlNode$Attribute@73219693],[common.apex.api.dom.XmlNode$NamespaceDef@777814a5],null,null,]), anyElement_type_info=(anyElement, urn:sobject.partner.soap.sforce.com, List<DOM.XmlNode>, 0, 1, true), apex_schema_type_info=(urn:sobject.partner.soap.sforce.com, true, false), field_order_type_info=(type_x, fieldsToNull, Id, anyElement), fieldsToNull=(), fieldsToNull_type_info=(fieldsToNull, urn:sobject.partner.soap.sforce.com, string, 0, -1, true), type_x=Account, type_x_type_info=(type, urn:sobject.partner.soap.sforce.com, string, 1, 1, false)]).

Here I am doing Salesforce to Salesforce integration with SOAP using Partner WSDL. Here I want to query Account records from one org to another org. Here using query_Http method to query records. And we are getting results as mentioned above(as expected).

From the above result I want to fetch only account record information (Id, Name fields) from the response body and store that result into Account object.

3
  • 3
    What does "split" mean? Could you please be very specific about what you are trying to do and how it is not working, by editing your question?
    – David Reed
    Jan 16, 2020 at 14:53
  • Hi @DavidReedlink, I updated above question. Can you please help on it.
    – user78027
    Jan 17, 2020 at 14:16
  • I do not know the answer to your question. I asked you to improve it so that the community can assist you.
    – David Reed
    Jan 17, 2020 at 14:49

1 Answer 1

1

It isn't 100% clear what the question is, but it seems like the desired outcome with anything like this is to access the results from the SOQL query.

All the results, with the exception of the ID field, will be in the anyElement response.

Something like SOAP UI can make it much easier to see what is going on here. E.g.

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>00D300000000001!AQ0AQIMZA1.Not.A.Real.SessionId.0U60FY5wRwIPGp</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>Select Id, Name, phone from Account limit 10</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.partner.soap.sforce.com">
   <soapenv:Header>
      <LimitInfoHeader>
         <limitInfo>
            <current>55</current>
            <limit>15000</limit>
            <type>API REQUESTS</type>
         </limitInfo>
      </LimitInfoHeader>
   </soapenv:Header>
   <soapenv:Body>
      <queryResponse>
         <result xsi:type="QueryResult">
            <done>true</done>
            <queryLocator xsi:nil="true"/>
            <records xsi:type="sf:sObject">
               <sf:type>Account</sf:type>
               <sf:Id>0014000001djEgKAAU</sf:Id>
               <sf:Id>0014000001djEgKAAU</sf:Id>
               <sf:Name>Test Account 1</sf:Name>
               <sf:Phone xsi:nil="true"/>
            </records>
            <records xsi:type="sf:sObject">
               <sf:type>Account</sf:type>
               <sf:Id>0014000001djEquAAE</sf:Id>
               <sf:Id>0014000001djEquAAE</sf:Id>
               <sf:Name>Test Account 2</sf:Name>
               <sf:Phone xsi:nil="true"/>
            </records>
            <size>2</size>
         </result>
         <!-- ... -->
      </queryResponse>
   </soapenv:Body>
</soapenv:Envelope>

Ignoring the duplicate <sf:ID> elements that get produced, you can see the type, Id, Name, and Phone elements per record that is returned. So we just need to iterate those out of the anyElement xml nodes.

partnerSoapSforceCom.Soap partner = new partnerSoapSforceCom.Soap();
partner.endpoint_x = URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/u/42.0';
partner.SessionHeader = new partnerSoapSforceCom.SessionHeader_element();
partner.SessionHeader.SessionId = UserInfo.getSessionId();

string query1 = 'Select Id, Name, Phone from Account limit 2';
partnerSoapSforceCom.QueryResult qr = new partnerSoapSforceCom.QueryResult();


qr =  partner.query_http(query1);
List<sobjectPartnerSoapSforceCom.sObject_x> sobjectlist =  qr.records;
for(sobjectPartnerSoapSforceCom.sObject_x aa : sobjectlist ){
    system.debug('aa.type_x---'+aa.type_x);
    //system.debug('aa.fieldsToNull---'+aa.fieldsToNull); 
    //system.debug('aa.anyElement---'+aa.anyElement); 

    for(DOM.XmlNode anyNode : aa.anyElement) {
        System.debug(anyNode.getName() + ' - ' + anyNode.getText());
    }
}

This produces:

10:39:24.155 (242639431)|USER_DEBUG|[13]|DEBUG|aa.type_x---Account
10:39:24.155 (242716094)|USER_DEBUG|[18]|DEBUG|Id - 0014000001djEgKAAU
10:39:24.155 (242743481)|USER_DEBUG|[18]|DEBUG|Name - Test Account 1
10:39:24.155 (242765054)|USER_DEBUG|[18]|DEBUG|Phone - 
10:39:24.155 (242791074)|USER_DEBUG|[13]|DEBUG|aa.type_x---Account
10:39:24.155 (242817168)|USER_DEBUG|[18]|DEBUG|Id - 0014000001djEquAAE
10:39:24.155 (242839268)|USER_DEBUG|[18]|DEBUG|Name - Test Account 2
10:39:24.155 (242859556)|USER_DEBUG|[18]|DEBUG|Phone - 

You must log in to answer this question.