+ Start a Discussion
Web DepartmentWeb Department 

No "fields" attribute (to access the results) in Partner WSDL query response

I'm following this (https://developer.salesforce.com/page/Tksample.php) tutorial and trying to performing a simple query with my SforcePartnerClient object...
$query = "SELECT Id, FirstName FROM Contact"
$response = $mySforceConnection->query($query);
foreach ($response->records as $record)
{
	echo $record->fields->FirstName;
}
...but the above code doesn't output anything. Looking at it in the debugger shows that "fields" is null. It DOES, however, seem to have the proper SOAP results inside "$record->any".

Any idea what might be wrong?
Pat PattersonPat Patterson
To save memory with large result sets, the raw response is not fully parsed in the query() call. You need to write your loop like this:

$queryResult = new QueryResult($response);
for ($queryResult->rewind(); $queryResult->pointer < $queryResult->size; $queryResult->next()) {
    print_r($queryResult->current());
}

That sample code is out of date. I'll go update it right now.