Searches are evaluated from left to right and use Unicode (UTF-8) encoding. Text searches are case-insensitive. For example, searching for Customer, customer, or CUSTOMER all return the same results.
Note that special types of text expressions (such as macros, functions, or regular expressions) that are evaluated at run time are not allowed in the FIND clause.
A SearchQuery contains two types of text:
| Wildcard | Description |
|---|---|
| * | Use an asterisk (*) to match one or more characters at the middle or end of your search term. Do not use the asterisk at the beginning of a search term. If you are searching for a literal asterisk in a word or phrase, then escape the asterisk (precede it with the \ character). For example, a search for john* finds items that start with variations on the term john, such as, johnson or johnny. A search for ma* finds items with mary or marty. |
| ? | Use a question mark (?) to match one character at the middle or end of your search term. Do not use the question mark wildcard at the beginning of a search term. For example, a search for jo?n finds items with the word john or joan. |
You can use the following special operators to focus your text search.
| Operator | Description |
|---|---|
| " " | Use quotation marks around search terms to find an exact phrase match. This can be especially useful when searching for text with punctuation. For example, "acme.com" finds items that contain the exact text acme.com. A search for "monday meeting" finds items that contain the exact phrase monday meeting. |
| AND | Finds items that match all of the search terms. For example, john AND smith finds items with both the word john and the word smith. In most cases if an operator isn't specified, AND is the default operator. When searching articles, documents, and solutions, AND must be specified because OR is the default operator. Case-insensitive. |
| OR | Finds items with at least one of the search terms. For example, john OR smith finds items with either john or smith, or both words. Case-insensitive. |
| AND NOT | Finds items that do not contain the search term. For example, john AND NOT smith finds items that have the word john but not the word smith. Case-insensitive. |
| ( ) | Use parentheses around search terms in conjunction with logical
operators to group search terms. For example, you can search for:
|
Reserved characters, if specified in a text search, must be escaped (preceded by the backslash \ character) in order to be properly interpreted. An error occurs if you do not precede reserved characters with a backslash. This is true even if the SearchQuery is enclosed in double quotes.
For example, to search for the following text:
{1+1}:2
insert a backslash before each reserved character:
\{1\+1\}\:2
| Type of Search | Example(s) |
|---|---|
| Single term examples | FIND {MyProspect}
FIND {mylogin@mycompany.com} FIND {FIND} FIND {IN} FIND {RETURNING} FIND {LIMIT} |
| Single phrase | FIND {John Smith} |
| Term OR Term | FIND {MyProspect OR MyCompany} |
| Term AND Term | FIND {MyProspect AND MyCompany} |
| Term AND Phrase | FIND {MyProspect AND "John Smith"} |
| Term OR Phrase | FIND {MyProspect OR "John Smith"} |
| Complex query using AND/OR | FIND {MyProspect AND "John Smith"
OR MyCompany}
FIND {MyProspect AND ("John Smith" OR MyCompany)} |
| Complex query using AND NOT | FIND {MyProspect AND NOT MyCompany} |
| Wildcard search | FIND {My*} |
| Escape sequences | FIND {Why not\?} |
| Invalid or incomplete phrase (will not succeed) | FIND {"John Smith} |
FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, LeadFIND {map*} IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, LeadThe Force.com Apex Code Developer's Guide has more information about using SOSL and SOQL with Apex.