function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hemmhemm 

Fields Searched in SOSL when using RETURNING IN

I am doing SOSL queries similar to:

 

FIND {Cook} IN ALL FIELDS RETURNING Lead(Id, Name, Street, City, State, PostalCode, Country ORDER BY Name) 

 

The word "Cook" is located in a County__c field on the Lead object.  I was under the impression that I could still search in the County__c field (that's what ALL FIELDS does) even though I am not returning it.  The record I want is not being found using the above.  If I edit the record and put "Cook" into the PostalCode field, it finds it.

 

The issue is that County__c is not the only additional field that could be searched.  I want to search ALL FIELDS but only return some fields so that the returned SOAP message is not so big.

 

Do I have to include every field I want to search in the RETURNING clause if I am doing my SOSL with the above syntax?

SusanKSusanK

hemm: What's the field type for County__c?  Some field types are not indexed for searching, which would prevent your query from matching.  Commonly used field types that are not indexed include picklist, lookup (i.e. the name of the record associated via lookup is not indexed), and formula.  Is County__c one of those?

 

Also, as a best practice, if you know that the query will be on one of these non-indexed fields, or you only want to match in one particular field, it's better to use SOQL.  SOSL does not allow you to specify what field you're matching in, so it can generate spurious results.

 

 

hemmhemm
Yes, it's a picklist field.  I thought those were indexed.  My bad.  I tried it using a custom text field and it worked fine.