- Search is the no.1 most used Salesforce feature.
- The
search index
andtokens
allow the search engine to apply advanced features like spell correction, nicknames, lemmatization, and synonym groups. Lemmatization
identifies and returns variants of the search term, such asadd
,adding
, andadded
, in search results.)- The search index also provides the opportunity to introduce relevance ranking into the mix.
- In general, you need a
custom search solution
when your org uses a custom UI instead of the standard Salesforce UI.
Salesforce Object Query Language (SOQL)
Salesforce Object Search Language (SOSL)
Suggested records API
- e.g. auto-suggestion, instant results, type-aheadSalesforce Federated Search
- search records stored outside of Salesforce.
-
Use SOQL when you know in which objects or fields the data resides and you want to:
- Retrieve data from a single object or from multiple objects that are related to one another.
- Count the number of records that meet specified criteria.
- Sort results as part of the query.
- Retrieve data from number, date, or checkbox fields.
-
Use SOSL when you don’t know in which object or field the data resides and you want to:
- Retrieve data for a specific term that you know exists within a field. Because SOSL can tokenize multiple terms within a field and build a search index from this, SOSL searches are faster and can return more relevant results.
- Retrieve multiple objects and fields efficiently, and the objects might or might not be related to one another.
- Retrieve data for a particular division in an organization using the divisions feature, and you want to find it in the most efficient way possible.
Query (REST) and query() (SOAP)
— Executes a SOQL query against the specified object and returns data that matches the specified criteria.Search (REST) and search() (SOAP)
— Executes a SOSL text string search against your org’s data.- REST API Developer Guide
- Syntax
FIND {term} RETURNING ObjectTypeName
- Example
FIND {march 2016 email} RETURNING Campaign
- Syntax
FIND {term} RETURNING ObjectTypeName1, ObjectTypeName2, ObjectTypeNameYouGetTheIdea
- Example
FIND {recycled materials} RETURNING Product2, ContentVersion, FeedItem
- Example
FIND {pink hi\-top} RETURNING Merchandise__c
- You use SOQL for single object searches, when you know the fields to be searched, when the search term is an exact match for the field (no partial or out-of-order matches), when you need number, date, or checkbox field data, and when you’re looking for just a few results
- Search queries can be expensive. The more data you’re searching through and the more results you’re returning, the more you can slow down the entire operation.
- Basic strategies:
- Limit which data you’re searching through
- Limit which data you’re returning
- Example
FIND {jsmith@cloudkicks.com} IN EMAIL FIELDS RETURNING Contact
FIND {Cloud Kicks} RETURNING Account
FIND {Cloud Kicks} RETURNING Account(Name, Industry)
FIND {Cloud Kicks} RETURNING Account (Name, Industry ORDER BY Name)
FIND {Cloud Kicks} RETURNING Account (Name, Industry ORDER BY Name LIMIT 10)
FIND {Cloud Kicks} RETURNING Account (Name, Industry ORDER BY Name LIMIT 10 OFFSET 25)
FIND {Cloud Kicks} RETURNING Account (Name, Industry)
WITH DIVISION = 'Global'
FIND {race} RETURNING KnowledgeArticleVersion
(Id, Title WHERE PublishStatus='online' and language='en_US')
WITH DATA CATEGORY Location__c AT America__c
FIND {first place} RETURNING User (Id, Name),
FeedItem (id, ParentId WHERE CreatedDate = THIS_YEAR Order by CreatedDate DESC)
WITH NETWORK = '00000000000001'
Find {shoe} RETURNING Product2 WITH PricebookId = '01sxx0000002MffAAE'
Search Suggested Records
— Returns a list of suggested records whose names match the user’s search string. The suggestions resource provides a shortcut for users to navigate directly to likely relevant records, before performing a full search.Search Suggested Article Title Matches
— Returns a list of Salesforce Knowledge articles whose titles match the user’s search query string. Provides a shortcut to navigate directly to likely relevant articles before the user performs a search.SObject Suggested Articles for Case
— Returns a list of suggested Salesforce Knowledge articles for a case.
- Syntax for Search Suggested Article Title Matches
/vXX.X/search/suggestTitleMatches?q=search string&language=article language&publishStatus=article publication status
- Example for Search Suggested Article Title Matches
/vXX.X/search/suggestTitleMatches?q=race+tips&language=en_US&publishStatus=Online
- Response JSON
{
"autoSuggestResults" : [ {
"attributes" : {
"type" : "KnowledgeArticleVersion",
"url" : "/services/data/v30.0/sobjects/KnowledgeArticleVersion/ka0D00000004CcQ"
},
"Id" : "ka0D00000004CcQ",
"UrlName" : "tips-for-your-first-trail-race",
"Title" : "race tips",
"KnowledgeArticleId" : "kA0D00000004Cfz",
"isMasterLanguage" : "1",
} ],
"hasMoreResults" : false
}
- A search for one term in a synonym group returns results for all terms in the group. For example, a search for USB returns results for all terms in the synonym group, which contains
USB
,thumb drive
,flash stick
, andmemory stick
. - Setup | Quick Find box | Synonyms
- The maximum number of characters per term is 100.
- Your organization can create a maximum of 2,000 promoted terms.