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
Erica CoxErica Cox 

Using date in FIND of SOSL

I have the need to search for contacts with a match on last name, first name, birthdate, phone, or a number of custom fields.  The code is currently building a string for SOSL call that looks, in part, like this:
 
String sosl = 'FIND \' TestLast OR TestFirst OR (111) 222-3333 OR 2004-12-07\'
               IN ALL FIELDS RETURNING Contact ( id, firstname, lastname, phone, birthdate)';

List<List<SObject>> searchList = search.query(sosl);

The list returned only includes matches on firstname, lastname, and phone -- not on birthdate.  Are date fields searchable in SOSL?  Perhaps I am misunderstanding the documentation when it lists the follwing as a limitation of SOSL :  

--Number, date, or checkbox fields. To search for such information, use the query() call instead.

Since I am using query() I thought I was OK, but maybe not?


 
kiranmutturukiranmutturu
date fields are not searchable. query() call in the sence make use of SOQL to get the other type of fields which are not supported in SOSL. Here the Search.query() still in the scope of search() call of SOSL. You are simply building the dynamic SOSL at run time. List returned field values should be of type text/email but you can give a date value in the where condition like..
 
FIND {Joe Smith}
IN Name Fields
RETURNING lead (name, phone Where createddate = THIS_FISCAL_QUARTER)

Hope this helps...