【问题标题】:PHP SOAP Salesforce Sub QueryPHP SOAP Salesforce 子查询
【发布时间】:2016-07-12 14:42:44
【问题描述】:

我正在使用 SOAP 来查询我们的 Salesforce 数据库,并且可以查询和显示结果。但是我现在想使用关系查询(子查询)。我可以从查询中得到结果,但是在 PHP 中显示子查询结果很困难。

我正在做以下事情:

$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 时,我得到以下 Array repose:

["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" 
    } 
} 

【问题讨论】:

    标签: php arrays salesforce


    【解决方案1】:

    您应该能够通过以下方式访问联系人:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多