You need to sign in to do that
Don't have an account?
Not able to get individual names from SOQL query using PHP
Hi,
I'm trying to pull out the values from a query (just pulling 1 id,name in this case); it works fine when I print the full result, but when I try to get each one it doesnt work.
$queryResult = $mySforceConnection->query($query); $records = $queryResult->records; foreach ($records as $record) { $record = new SObject($record); $_id = $record->Id; $_name = $record->fields->Name; echo $_id; echo $_name; } foreach ($records as $record) { print_r($record); }
it outputs:
Notice: Trying to get property of non-object in /srv/home-www/salesforce/test.php on line 50
0
SObject Object ( [type] => Account [fields] => stdClass Object ( [Name] => TheStreet.com Inc ) [Id] => 0018000000ZIXKWAA5 )
Any ideas? Looked around and saw about 10 different ways to grab the info but none of them worked. Thanks!
Casey
Without seeing the query or the result of the print_r it's had to know what you're getting, but there is no need to cast the result records as sObjects. You should be able to reference them directly: $record->Id, $record->fields->Name, assuming that you are using the Partner API.
If that's not working please include the print_r output in your response.
Park
All Answers
Without seeing the query or the result of the print_r it's had to know what you're getting, but there is no need to cast the result records as sObjects. You should be able to reference them directly: $record->Id, $record->fields->Name, assuming that you are using the Partner API.
If that's not working please include the print_r output in your response.
Park
hi,
I'm currently trying these too, I'm able to retrieve the first SObject but having problems retrieving for the second one.
Array ( [0] => SObject Object ( [type] => Contact [fields] => stdClass Object ( [AccountId] => 001A0000002QNHTIA4 [Email] => spavlova@uog.com [Name] => Stella Pavlova [MobilePhone] => (212) 842-5501 [2] => SObject Object ( [type] => Account [fields] => stdClass Object ( [Name] => United Oil & Gas Corp. ) ) ) [Id] => 003A00000022j6dIAA ) ) [Id] => 003A00000022j6nIAA ) )
I'm currently using these to retrieve:
foreach( $queryResult->records as $account ){
$accountInfo = array();
$accountInfo['id'] = $account->Id;
$accountInfo['name'] = $account->fields->Name;
$accountInfo['email'] = $account->fields->Email;
$accountInfo['phone'] = $account->fields->MobilePhone;
$accountInfo['company'] = $account->fields->sobjects[2]->fields->Name;
//print_r( $accountInfo );
array_push( $values, $accountInfo );
}
Any thoughts?
Please take a look at this post which was asking the same question and includes a link to some sample code.
Park