String searchword ='Red';
String searchStr1 = '*'+searchword+'*';
String searchQuery = 'FIND \'' + searchStr1 + '\' IN ALL FIELDS RETURNING Product2(Id,Name)';
List<List<sObject>> searchConLead = search.query(searchQuery);
System.debug('searchConLead: '+searchConLead);

I need to get all the products that contain word "Red"

  • Is the word red in a custom rich text area field? – S.B. Apr 2 '20 at 23:55

SOSL only supports "starts with" matching, as per the documentation:

Asterisks match zero or more characters at the middle or end of your search term

Question marks match only one character in the middle or end of your search term

It isn't valid to put a wildcard at the start of the SOSL search term.

SOQL's % wildcard can be used at the start, in the middle and at the end of a search term, but clearly that is a different query technology and doesn't work for Shield Platform Encrypted fields (unlike SOSL).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.