+ Start a Discussion
Bhushan2710Bhushan2710 

Problem with SOSL Query

Hi,

I am doing a SOSL query to find the account records. My query is as below: 
string searchText;
string querySosl = 'FIND \'' +searchText+'*\' IN  ALL FIELDS RETURNING Account(Id,Name,BillingPostalCode,ShippingPostalcode,Website,AccountNumber)'; 
List<List<sObject>> searchList = search.query(querySosl);
System.debug('****searchList****** '+searchList);

The above query does not  returns me correct record as expected. 

So for example I have a Account Named : 512 Tech Limited
So when I search for  word 'Limited' nothing is returned to me.  But if  I search for '512'  the query returns the correct account. 
So is this a limitation of the SOSL query ?? or something else that is causing query to behave in this manner. 

Blake TanonBlake Tanon
it probably has something to do with the * after the seearchText.
Bhushan2710Bhushan2710
If you check the dynamic sosl example in salesforce doc.. * is specified there.
Blake TanonBlake Tanon
If Limited is the last part of the name you will return no results.  for the * to work, the name would have to be something like 'Limited Stuff'.
Vamsi KrishnaVamsi Krishna
try including the * before the searchText as well...

string querySosl = 'FIND \'*' +searchText+'*\' IN  ALL FIELDS RETURNING
Bhushan2710Bhushan2710
This is weird Now i fixed my query to remove the extra space between FIND and the backslash(\) , and its returning all the records having Limited string querySosl = 'FIND\'' +searchText+'*\' IN ALL FIELDS RETURNING Account(Id,Name,BillingPostalCode,ShippingPostalcode,Website, AccountNumber)'; Thanks all for you replies! Regards, Bhushan