父级对子级soql请求的结果

时间:2018-11-07 14:49:52

标签: json salesforce soql

我想知道如何显示soql子项到父项请求的结果。

$query = "SELECT FirstName, LastName, (select Retreat_Booking__c.Retreat__c from Retreat_Bookings__r)FROM Contact" 

$response = $mySforceConnection->query($query);   
$queryResult = new QueryResult($response);  
while($queryResult->current()->FirstName!='' || $queryResult->current()->LastName!='')
{
    echo $queryResult->current()->FirstName." ".$queryResult->current()->LastName." ".$queryResult->current()->Retreat__c." <BR/>";
    $queryResult->next();
}

该请求有效,并显示“名字”和“姓氏”,但不显示“ Retreat__c”。 我知道第二个选择的结果是一个json,我尝试了很多事情,但是没有用。

1 个答案:

答案 0 :(得分:0)

查询应如下所示

$query = "SELECT FirstName, LastName, (select Retreat_Booking__r.Retreat__c from Retreat_Bookings__c)FROM Contact";

Retreat_Booking__r.Retreat__c而不是Retreat_Booking__c.Retreat__c

from Retreat_Bookings__c而不是Retreat_Bookings__r

FROM之后,应该有一个自定义对象名称(扩展名为__cRetreat_Bookings__c,并从参考对象字段中检索数据,您应该使用__r扩展名因此Retreat_Booking__r.Retreat__c

更新

对于第二个问题,您可以尝试

$query = "SELECT FirstName, LastName, (select Retreat_Booking__r.Retreat__c from Retreat_Bookings__c) AS rb FROM Contact"

然后

while($queryResult->current()->FirstName!='' || `$queryResult->current()->LastName!='')
{
echo $queryResult->current()->FirstName." ".$queryResult->current()->LastName." ".$queryResult->current()->rb.Retreat__c" <BR/>";
$queryResult->next();
}`