我想知道如何显示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,我尝试了很多事情,但是没有用。
答案 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
之后,应该有一个自定义对象名称(扩展名为__c
)Retreat_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();
}`