Force.com-Toolkit-for-PHP icon indicating copy to clipboard operation
Force.com-Toolkit-for-PHP copied to clipboard

PHP 5.5.9 - Object Items as String

Open jasonabuck opened this issue 10 years ago • 1 comments

I have been running PHP Toolkit 20 for the longest time on PHP 5.3.8. I am in the process of migrating to a PHP 5.5.9 Server and am having big issues with the QueryResults.

============= START CODE =========== createConnection(SALESFORCE_WSDL); $mylogin = $mySforceConnection->login(SALESFORCE_USER, SALESFORCE_PASS . SALESFORCE_TOKEN); $query = "SELECT Id, Name, Account_Owner_Name__c, Membership_Owner_Name__c, Sales_Initiator_Name__c FROM Account LIMIT 1"; $options = new QueryOptions(200); $mySforceConnection->setQueryOptions($options); $response = $mySforceConnection->query($query); $queryResult = new QueryResult($response); !$done = false; echo "Size of records: ".$queryResult->size."\n ";; $i = 0; if ($queryResult->size > 0) { while (!$done) { foreach ($queryResult->records as $record) { // $namevalue = $record->fields->Name."\r\n"; var_dump($queryResult); ``` // REF 1: Line below works, but is putting all data in for string fields in record->any value. // echo "" . $i . "--AccountID: " . $record->Id[0] . " AccountName: " . $record->any . ""; // REF 2: Line below only returns record->Id value. Only if Id[0] and not ->Id as in old toolkit. ``` // echo "" . $i . "--AccountID: " . $record->Id[0] . " AccountName: " . $record->fields->Name . " AccountOwner: " . $record->fields->Account_Owner_Name__c . " MembershipOwner: " . $record->fields->Membership_Owner_Name__c . " SalesInitiator: " . $record->fields->Sales_Initiator_Name__c . ""; $i++; } if ($queryResult->done != true) { echo "****\* Get Next Chunk *****\n"; try { $response = $mySforceConnection->queryMore($queryResult->queryLocator); $queryResult = new QueryResult($response); } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } } else { $done = true; } } } } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } ?>

==============END CODE ==============

The Query: $query = "SELECT Id, Name, Account_Owner_Name__c, Membership_Owner_Name__c, Sales_Initiator_Name__c FROM Account LIMIT 1"; object(QueryResult)#41 (6) { ["queryLocator"]=> NULL ["done"]=> bool(true) ["records"]=> array(1) { [0]=> object(stdClass)#42 (3) { ["type"]=> string(7) "Account" ["Id"]=> array(2) { [0]=> string(18) "0015000000lBvMaAAK" [1]=> string(18) "0015000000lBvMaAAK" } ["any"]=> string(242) "Kvh Industries, Inc.Erik AbergKevin GrahamAdam Herbert" } } ["size"]=> int(1) ["pointer"]=> int(0) ["sf":"QueryResult":private]=> bool(false) } My var_dump of the query returns all the fields from Name to Sales_Initiator_Name__c as a string that is concatenated. (EG. REF 1) I would like to get REF 2 working, NULLs are returned for $record->fields->Sales_Initiator_Name__c or $record->Sales_Initiator_Name__c

Any ideas on how to update the toolkit to work with PHP 5.5.9 or higher. The above functionality is working with no issues on PHP 5.3.8

Thanks,

Jason

jasonabuck avatar Jul 12 '15 15:07 jasonabuck

Found this post (http://stackoverflow.com/questions/15698362/trouble-with-salesforce-query-results-php-toolkit)

Fixed my issues.

Not sure if this affected the fix, but I downloaded the SOAPCLIENT (Folder from this FORK).

This is the new and working code.

================== START CODE ================

createConnection(SALESFORCE_WSDL); $mylogin = $mySforceConnection->login(SALESFORCE_USER, SALESFORCE_PASS . SALESFORCE_TOKEN); $query = "SELECT Id, Name, Account_Owner_Name__c, Membership_Owner_Name__c, Sales_Initiator_Name__c FROM Account "; $options = new QueryOptions(200); $mySforceConnection->setQueryOptions($options); $response = $mySforceConnection->query($query); $queryResult = new QueryResult($response); !$done = false; echo "Size of records: ".$queryResult->size."\n ";; $i = 0; if ($queryResult->size > 0) { while (!$done) { foreach ($queryResult->records as $record) { ``` $sObject = new SObject($record); $AccountID = $sObject->Id; $AccountName = $sObject->fields->Name; $AccountOwnerName = $sObject->fields->Account_Owner_Name__c; $AccountMembersOwnerName = $sObject->fields->Membership_Owner_Name__c; $AccountSalesInitiator = $sObject->fields->Sales_Initiator_Name__c; ``` echo "" . $i . "--AccountID: " . $AccountID . " AccountName: " . $AccountName . " AccountOwner: " . $AccountOwnerName . " MembershipOwner: " . $$AccountMembersOwnerName . " SalesInitiator: " . $AccountSalesInitiator . ""; ``` $i++; } if ($queryResult->done != true) { echo "***** Get Next Chunk *****\n"; try { $response = $mySforceConnection->queryMore($queryResult->queryLocator); $queryResult = new QueryResult($response); } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } } else { $done = true; } } ``` } } catch (Exception $e) { print_r($mySforceConnection->getLastRequest()); echo $e->faultstring; } ?>

=================== END CODE ===================

jasonabuck avatar Jul 12 '15 16:07 jasonabuck