7

Can I use relationships in SOSL?

Example: Find all first names that start with 'Roc' within Position__c

FIND \'Roc*\' IN ALL FIELDS RETURNING Position__c(Id, Contact__r.FirstName WHERE Title__c = 'Paper Jammer')

1 Answer 1

8

SOSL does not support traversing relationship query .

When you write a query as below

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

You will notice that owner.Alias will be null but you will still get ownerId and you can use ownerId to further form queries .

8
  • So is this only on standard relationships? not custom?
    – fourq
    Dec 7, 2012 at 17:35
  • i think it will work for all Dec 7, 2012 at 17:47
  • I just checked you still get ownerId and i think you will need to run another query here .I am editing the answer . I still suspect something changed in releases as this answer is nearly three years back .Updating the answer now May 17, 2016 at 16:18
  • Maybe a bit late to the party, but does this apply to the condition in the "where" clause as well? Is this documented? Oct 21, 2022 at 1:56
  • 1
    FYI I discovered an answer on the Salesforce forums dated from 2009 in which the author of one answer says that the query works if you specify the namespace on the custom objects (for the fields this is not necessary). Nov 1, 2022 at 18:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .