简体   繁体   中英

Trouble displaying results of sub query with php using salesforce SOAP api and partner wsdl

Here's a generic query sample that represents my problem.

$query = "SELECT Account.Name, Name from Contract WHERE AccountId = '001U0000003q6scIAA'";
$response = $mySforceConnection->query($query);

foreach ($response->records as $record) {
$sObject = new SObject($response->records[0]);
var_dump($sObject);
echo $sObject->sobjects[0]->Name."<br/>\n";
echo $record->fields->Name."<br/>\n";
echo "*******************************<br/>\n";
echo "*******************************<br/>\n";
}

The problem is that the Account.Name field will not display. Just in case my entire method is wrong, The idea is to grab all of the contracts assigned to a specific account and display both the account name and the pertinent info from the contract. (so far all contract fields display perfectly. Just can't display the account name)

Thanks for the assistance in advance!

Here's the var_export().. (I removed all of my custom fields)

SObject::__set_state(array( 'type' => 'Contract', 'fields' => stdClass::__set_state(array(
'AccountId' => '001U0000003q6scIAA', 'Name' => 'test contract', '1' =>
SObject::__set_state(array( 'type' => 'Account', 'fields' => stdClass::__set_state(array( 
'Name' => 'test Account name', )), )), )), ))

Here's the var_dump() ...

object(SObject)#5 (2) { ["type"]=> string(8) "Contract" ["fields"]=> object(stdClass)#1871 (14) {
["AccountId"]=> string(18) "001U0000003q6scIAA" ["Name"]=> string(18) "Test Contract Name"
["1"]=> object(SObject)#1869 (2) { ["type"]=> string(7) "Account" ["fields"]=> object(stdClass)#1870 (1) { ["Name"]=> string(15) "Account Name" } } } }

So I finally found something that put me on the right path. here's how I solved it...

foreach ($response->records as $record) {
    echo $record->fields->{1}->fields->Name."<br/>\n";
    echo $record->fields->Name."<br/>\n";
    echo "*******************************<br/>\n";
    echo "*******************************<br/>\n";
}

I had tried this approach originally but without the {} which gave an error. So all you have to do is look at the print_r() output, change the number to the number it gives you here - ["1"]=> object(SObject)#1869 and this query will show!

Thanks Daan for trying to help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM