function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sideburnsideburn 

query for account id

Hi, I have the following code to get the owner id from an account:

$query_str = "select 'OwnerId' from 'account' where Name = 'The Company Name'";

$result = $client->query($query_str,1)
while (list($k1, $record) = each($result->records)) {
printf(":: %s",$record);
}
this is the output result:

:: Account
::
:: 00530000000QJjmAAG

It works but all I want is the account ID itself not the other 2 strings. Can someone explain why this is happenening? (I'm just trying to get an account ID from an account Name)...Thanks.

Message Edited by sideburn on 02-23-2006 01:31 AM

Tran ManTran Man


sideburn wrote:
Hi, I have the following code to get the owner id from an account:

$query_str = "select 'OwnerId' from 'account' where Name = 'The Company Name'";

$result = $client->query($query_str,1)
while (list($k1, $record) = each($result->records)) {
printf(":: %s",$record);
}
this is the output result:

:: Account
::
:: 00530000000QJjmAAG

It works but all I want is the account ID itself not the other 2 strings. Can someone explain why this is happenening? (I'm just trying to get an account ID from an account Name)...Thanks.

Message Edited by sideburn on 02-23-2006 01:31 AM





Try printf(":: %s", $record->Id);
sideburnsideburn
that doesnt work.. if i do printf(":: %s",$k1);

I get:

:: type
:: Id
:: OwnerId
Tran ManTran Man
Can you var_dump the value of $result?
sideburnsideburn
yeah, I get this:

object(stdClass)(4) { ["done"]=> string(4) "true" ["queryLocator"]=> string(0) "" ["records"]=> &object(stdClass)(3) { ["type"]=> string(7) "Account" ["Id"]=> string(0) "" ["OwnerId"]=> string(18) "00530000000p0A8AAI" } ["size"]=> string(1) "1" }
Tran ManTran Man
Here's some code from the PHP5 SOAP toolkit that I am working on that might help. You can ignore the first 3 lines:

$query = "SELECT Id,Name,BillingCity,BillingState,Phone,Fax from Account";
$queryOptions = new QueryOptions(500);
$response = $mySforceConnection->query(($query), $queryOptions);

if ($response->size > 0) {
if ($response->size == 1) {
$recs = array ($response->records
);
} else {
$recs = $response->records;
}
}

foreach ($recs as $r) {
echo $r->Id;
}
sideburnsideburn
I tried your code but all I get on the output is:

Array
SynchroSynchro
Try doing a var_dump() on that instead of just echo or print.
Park Walker (TAGL)Park Walker (TAGL)
The reason that this is happening is that your query only returns one record, rather than an array of records. When you loop through the return value you get each field rather than each record. This is a generic problem with query results: you need to test if the result contains 0,1, or more records and handle it accordingly.


Try the following:


$query_str = "select OwnerId from Account where Name = 'Whatever'";
$result = $client->query(array("queryString" => $query_str));
if ($result) {
$item = $result->result;
if ($item->size == 1) {
$recs = array($item->records);
} else {
$recs = $item->records;
}
} else {
$recs = array();
}
var_dump($recs);
foreach($recs as $rec) {
print("OwnerId is ".$rec->OwnerId."\r\n");
}



This works with the native SOAP API in PHP5, possibly not with other packages, but you'll get the idea.

Message Edited by Redsummit on 02-24-2006 10:34 AM