我们可以在SOSL查询中建立关系吗?

时间:2012-05-07 14:09:14

标签: salesforce apex-code

我想使用SOSL获取关系值?

List<List<SObject>> searchList = [FIND :mySearchText IN ALL FIELDS 
                              RETURNING 
                                 Account (id, name,phone, BillingStreet,BillingCity,BillingState, ownerID.Alias,ownerID.MobilePhone )];

我收到错误

Save error: Didn't understand relationship 'ownerID' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the  describe call for the appropriate names.

我有什么问题吗?

1 个答案:

答案 0 :(得分:4)

您可以访问该关系,但需要使用Owner.UserField而不是OwnerId.UserField

这应该适合你:

List<List<Account>> searchList = [FIND 'test' IN ALL FIELDS RETURNING 
    Account (id, name, phone, BillingStreet, BillingCity, BillingState, 
    OwnerId, Owner.Alias, Owner.MobilePhone)];

system.debug(searchList[0][0].Owner.Alias);
system.debug(searchList[0][0].Owner.MobilePhone);