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
JimAJimA 

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);
foreach ($queryResult->records as $record) {
 
 
 echo $record->fields->FirstName;
 echo $record->Account->fields->ParentId;

}
Best Answer chosen by Admin (Salesforce Developers) 
Lawrence-CECLawrence-CEC

Oops, sorry, that should be "$record" not "$results" ... so:

 

echo $record->fields->{1}->fields->ParentId;

 

 for that last line there.

 

All Answers

SuperfellSuperfell
wouldn't it be
echo $record->fields->Account->fields->ParentId;
JimAJimA
Hi Simon,
 
Thanks so much for the post.
 
I tried $record->fields->Account->fields->ParentId; with no luck. I was thinking you didnt need account in there because its another field called Type.  It looks like the results have a 2nd SObject Object and with PHP Toolkit 11.0 it would have been $sobject->sobjects[0]->fields->ParentId  but that was when you used the $sObject = new SObject($record) call.
 
 
THis is the record when I use print_r() function:
 
SObject Object ( [type] => Contact [fields] => stdClass Object ( [FirstName] => Tom [LastName] => Someone [1] => SObject Object ( [type] => Account [fields] => stdClass Object ( [ParentId] => 00130000009AM3AKKK) ) ) )
 
Thanks
Jim
Lawrence-CECLawrence-CEC

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

JimAJimA

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:

 

SObject Object
(
    [type] => Contact
    [fields] => stdClass Object
        (
            [FirstName] => Richard
            [LastName] => Tieu
            [1] => SObject Object
                (
                    [type] => Account
                    [fields] => stdClass Object
                        (
                            [ParentId] => 00130000007yYd0AAE
                        )

                )

        )

)

Fatal error: Cannot use object of type stdClass as array in D:\websites\web_admin\events\jobs\test.php on line 23
Lawrence-CECLawrence-CEC

Ok, try this:

 

 

$results->fields->{1}->fields->ParentId

 

 

 

JimAJimA

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; }

 

 

Lawrence-CECLawrence-CEC

Oops, sorry, that should be "$record" not "$results" ... so:

 

echo $record->fields->{1}->fields->ParentId;

 

 for that last line there.

 

This was selected as the best answer
JimAJimA

Hi Lawrence,  You totally rock!  I never would have thought to use {1}. 

 

Thanks again!