You need to sign in to do that
Don't have an account?
JimA
}
PHP Toolkit 13.0 - Access Sub Query values
Does any one know how to access the Account.ParentId Value? I keep getting an error with the code below but I can access the FirstName value fine.
Thanks!
$strSQL = "SELECT FirstName, LastName, Account.ParentId FROM Contact WHERE Memberships__c INCLUDES ('Fixed Income Directory') ";
$response = $mySforceConnection->query($strSQL);
$queryResult = new QueryResult($response);
$response = $mySforceConnection->query($strSQL);
$queryResult = new QueryResult($response);
foreach ($queryResult->records as $record) {
echo $record->fields->FirstName;
echo $record->Account->fields->ParentId;
echo $record->fields->FirstName;
echo $record->Account->fields->ParentId;
}
Oops, sorry, that should be "$record" not "$results" ... so:
echo $record->fields->{1}->fields->ParentId;
All Answers
echo $record->fields->Account->fields->ParentId;
Based on your output from print_r(), it looks like this should work:
$record->fields[1]->fields->ParentId;
If that doesn't work, try wrapping the print_r() output in a <pre>...</pre> block to make the nesting easier to see.
-L
Hi Lawrence,
Thanks so much for the help. I did try that with no luck. I did add the PRE tag and here is what i get and also the error I get when I try you line of code:
Ok, try this:
$results->fields->{1}->fields->ParentId
No luck, results below. I pasted in my code also if that helps at all. Thanks for the help!
SObject Object ( [type] => Contact [fields] => stdClass Object ( [FirstName] => Richard [LastName] => Tieu [1] => SObject Object ( [type] => Account [fields] => stdClass Object ( [ParentId] => 00130000007yYd0AAE ) ) ) ) Notice: Undefined variable: results in D:\websites\web_admin\events\jobs\test.php on line 23 Notice: Trying to get property of non-object in D:\websites\web_admin\events\jobs\test.php on line 23 sf_connect(); $strSQL = "SELECT FirstName, LastName, Account.ParentId FROM Contact WHERE Memberships__c INCLUDES ('Fixed Income Directory') "; $response = $mySforceConnection->query($strSQL); $queryResult = new QueryResult($response); //print_r($queryResult); foreach ($queryResult->records as $record) { echo "<pre>"; print_r($record)."</pre><br><br>"; echo $results->fields->{1}->fields->ParentId; }
Oops, sorry, that should be "$record" not "$results" ... so:
echo $record->fields->{1}->fields->ParentId;
Hi Lawrence, You totally rock! I never would have thought to use {1}.
Thanks again!