The following are examples of text searches that use SOSL.
Look for joe anywhere in the system. Return the IDs of the records where joe is found.
FIND {joe}
Look for the name Joe Smith anywhere in the system, in a case-insensitive search. Return the IDs of the records where Joe Smith is found.
FIND {Joe Smith}
Look for the name Joe Smith in the name field of a lead, return the ID field of the records.
FIND {Joe Smith}
IN Name Fields
RETURNING lead
Look for the name Joe Smith in the name field of a lead and return the name and phone number.
FIND {Joe Smith}
IN Name Fields
RETURNING lead(name, phone)
Look for the name Joe Smith in the name field of a lead. Return the name and phone number of any matching record that was also created in the current fiscal quarter.
FIND {Joe Smith}
IN Name Fields
RETURNING lead (name, phone Where createddate = THIS_FISCAL_QUARTER)
Look for the name Joe Smith or Joe Smythe in the name field of a lead or contact and return the name and phone number. If a people record is called Joe Smith or Joe Smythe, that record isn’t returned.
FIND {"Joe Smith" OR "Joe Smythe"}
IN Name Fields
RETURNING lead(name, phone), contact(name, phone)
Wildcards:
FIND {Joe Sm*}
FIND {Joe Sm?th*}
Delimiting “and” and “or” as literals when used alone:
FIND {"and" or "or"}
FIND {"joe and mary"}
FIND {in}
FIND {returning}
FIND {find}
Escaping special characters & | ! ( ) { } [ ] ^ " ~ * ? : \ ' + -
FIND {right brace \}}
FIND {asterisk \*}
FIND {question \?}
FIND {single quote \'}
FIND {double quote \"}
note: Apex requires that you surround SOQL and SOSL statements with square brackets to use them in your statements. You can use Apex script variables and expressions when preceded by a colon (:).
See Also