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.

1FIND {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.

1FIND {Joe Smith}

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

1FIND {Joe Smith}
2IN Name Fields
3RETURNING lead

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

1FIND {Joe Smith}
2IN Name Fields
3RETURNING lead(name, phone)

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.

1FIND {Joe Smith}
2IN Name Fields
3RETURNING 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 an opportunity is called Joe Smith or Joe Smythe, the opportunity should not be returned.

1FIND {"Joe Smith" OR "Joe Smythe"}
2IN Name Fields
3RETURNING lead(name, phone), contact(name, phone)

Wildcards:

1FIND {Joe Sm*}
2FIND {Joe Sm?th*}

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

1FIND {"and" or "or"}   
2FIND {"joe and mary"}   
3FIND {in}
4FIND {returning}
5FIND {find}

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

1FIND {right brace \}}
2FIND {asterisk \*}
3FIND {question \?}
4FIND {single quote  \'}
5FIND {double quote  \"}

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 (:).

Note