Print this page

Searching Lookup Fields in SOSL queries

Knowledge Article Number 000176100
Description In SOSL you can't search by string value of a Lookup field.

For Example:

I have a record in object Contact:
Name: David Sidhu

Now i have a related object "LookUpToContact" looking up to parent object Contact.

If I try to search "David Sidhu" using SOSL in LookUpToContact Query will be like:

String searchName = 'FIND {David*} IN ALL FIELDS RETURNING LookUptoContact__c(Id, Contact__r.FirstName)';

But it Returns nothing, just an error (can be verified using workbench).

 
Resolution This error occurs because in SOSL you Can't search on Lookup fields (However, you can return lookup field values).
You can search only by fields of Objects being used in the RETURNING clause.




promote demote