2016-07-12 71 views
1

我正在使用SOAP來查詢我們的Salesforce數據庫,並且可以查詢並顯示結果。不過,我現在想使用關係查詢(子查詢)。我可以從查詢中獲得結果,但努力在PHP中顯示子查詢結果。PHP SOAP Salesforce子查詢

我做了以下內容:

$Query = "SELECT Account.Name, (SELECT Contact.Name, Contact.accountId FROM contacts) FROM Account WHERE Name Like '%Test Client%'"; 
    $Response = $SforceConnection->query($Query); 

    foreach ($Response->records as $RecordSet) { 
    echo "$RecordSet->Name."<br />"; 
    } 

我可以顯示的公司名稱就好了,但奮力顯示像Contact.Name和Contact.accountId子查詢數據。我不確定顯示這兩個字段的正確語法。

當我運行SQL我得到下面的數組養神:

["queryLocator"]=> NULL ["done"]=> bool(true) ["records"]=> array(1) { 
    [0]=> object(stdClass)#10 (3) { 
     ["Id"]=> NULL ["Contacts"]=> object(stdClass)#11 (4) { 
      ["done"]=> bool(true) ["queryLocator"]=> NULL ["records"]=> array(1) { 
       [0]=> object(stdClass)#12 (3) { 
        ["Id"]=> NULL ["AccountId"]=> string(18) "0015800000UU25zAER" ["Name"]=> string(16) "Test Users" } 
       } 

      ["size"]=> int(1) 
     } ["Name"]=> string(15) "Test Client" 
    } 
} 

回答

0

您應該能夠訪問下列方式聯繫人:

if (isset($RecordSet->Contacts) && isset($RecordSet->Contacts->records) && !empty($RecordSet->Contacts->records)) { 
    foreach($RecordSet->Contacts->records as $contact) { 
    echo $contact->Name; 
    } 
}