Newer Version Available

This content describes an older version of this product. View Latest

Example Text Searches

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.

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.

Look for the name Joe Smith in the name field of a lead, return the ID field of the records.

Look for the name Joe Smith in the name field of a lead and return the name and phone number.

Look for the name Joe Smith in the name field of a lead and return the name and phone number of any matching record that was also created in the current 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 an opportunity is called Joe Smith or Joe Smythe, the opportunity should not be returned.

Wildcards:

Delimiting “and” and “or” as literals when used alone:

Escaping special characters & | ! ( ) { } [ ] ^ “ ~ * ? : \ '

Apex requires that you surround SOQL and SOSL statements with square brackets to use them on the fly. You can use Apex script variables and expressions when preceded by a colon (:).

Note