I use force explorer to query datas, it works well.

My query :

`$query_result = $mySforceConnection->query("SELECT Metier__c, Profil__c, Secteur__c, TypeContrat__c, Id FROM Opportunity");`

echo "<pre>";
echo "</pre>";

My response :


public 'queryLocator' => string '01g2000001Mav0cAAB-2000' (length=23) public 'done' => boolean false public 'records' => array (size=2000) 0 => object(stdClass)[6] public 'Id' => string '0062000000Ye3ZLAAZ' (length=18) 1 => object(stdClass)[7] public 'Id' => string '0062000000Ye3ZMAAZ' (length=18) 2 => object(stdClass)[8] public 'Id' => string '0062000000Ye3ZNAAZ' (length=18) 3 => ... public 'size' => int 17202 public 'pointer' => int 0 private 'sf' => object(SforceEnterpriseClient)[1] protected 'sforce' => object(SoapClient)[2] public 'trace' => int 1 public 'compression' => int 32 public '_encoding' => string 'utf-8' (length=5) public '_features' => int 1 public '_user_agent' => string 'salesforce-toolkit-php/27.0' (length=27) public '_soap_version' => int 1 public 'sdl' => resource(10, Unknown) public '__last_request_headers' => string 'POST /services/Soap/c/27.0/00D20000000CpAr HTTP/1.1

Host: emea.salesforce.com

Connection: Keep-Alive

User-Agent: salesforce-toolkit-php/27.0

Accept-Encoding: gzip, deflate

Content-Type: text/xml; charset=utf-8

SOAPAction: ""

Content-Length: 563


' (length=265) public '__last_response_headers' => string 'HTTP/1.1 200 OK

Date: Tue, 10 Feb 2015 09:51:02 GMT

Set-Cookie: BrowserId=Ph7Kgw0mQyCEBBahrCXleQ;Path=/;Domain=.salesforce.com;Expires=Sat, 11-Apr-2015 09:51:02 GMT

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Type: text/xml;charset=UTF-8

Content-Encoding: gzip

Content-Length: 17897

' (length=293) public '_cookies' => array (size=1) ... public 'location' => string 'https://emea.salesforce.com/services/Soap/c/27.0/00D20000000CpAr' (length=64) public '__default_headers' => array (size=1) ... public '__last_request' => string ' xxxxxxxxxxxxxxxxxxxxxxxSELECT Metier__c, Profil__c, Secteur__c, TypeContrat__c, Id FROM Opportunity resource(13, stream) public '_use_proxy' => int 0 public 'httpurl' => resource(14, Unknown)


      public '__last_response' => string '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:sf="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><queryResponse><result><done>false</done><queryLocator>01g2000001Mav0cAAB-2000</queryLocator><records xsi:type="sf:Opportunity"><sf:Id>0062000000Ye3ZLAAZ</sf:Id><sf:Metier__c>Maintenance Indus / Industrie Production</sf:Metier__c><sf:Profil_'... (length=531749)
  protected 'sessionId' => string '00D20000000CpAr!AQQAQIn39F2oRBB1oQK7.NcjV_K06gsa03Gc8j5Vud5k9XrOk_CJJsSFVaQZ7csDJUVUrQ5qoeepQs6QpCFR5UOGmRJzFsnd' (length=112)

As you see, i got a loong list of object as respnse, inside it i have 2 soap enveloppe.

MY QUESTION : How can i get only the second soap response (inside public '__last_response') so i can parse it after?

Thank for your help

  • Hello, i found it : $last_response = $mySforceConnection->getLastResponse()
    – esydev
    Feb 10, 2015 at 10:28

1 Answer 1


Due to some formatting flaws in your question it's very hard to read and I was not able to fix it. If possible try to rework your indentation, so that the markdown here detects your response-dumps as source-code...

This said, generally I don't understand your approach at all. Why do you care about XML parsing at all when you get the response nicely packaged into php objects out of the box?

What I usually do is this:

require_once ('../yourPathTo/soapclient/SforcePartnerClient.php');
define("USERNAME", "you@wherever.com");
define("PASSWORD", "yourPassword");
define("SECURITY_TOKEN", "yourToken");
$GLOBALS[sfBatchSize] = 100;
$GLOBALS[sfConnection] = new SforcePartnerClient();

$query = "SELECT Metier__c, Profil__c, Secteur__c, TypeContrat__c, Id FROM Opportunity ";
$response = $GLOBALS[sfConnection]->query($query);
$records = $response->records;
while(!$response->done) {
    $response = $GLOBALS[sfConnection]->queryMore($response->queryLocator);
    $records = array_merge($records, $response->records);    

Then in $records should be what you need.

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.