Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

SuggestionOption Class

Options that narrow record and article suggestion results returned from a call to System.Search.suggest(String, String, Search.SuggestionOption).

Namespace

Search

SuggestionOption Methods

The following are methods for SuggestionOption.

setFilter(knowledgeSuggestionFilter)

Set filters that narrow Salesforce Knowledge article results in a call to System.Search.suggest(String, String, Search.SuggestionOption).

Signature

public void setFilter(Search.KnowledegeSuggestionFilter knowledgeSuggestionFilter)

Parameters

Return Value

Type: void

Usage

1Search.KnowledgeSuggestionFilter filters = new Search.KnowledgeSuggestionFilter(); 
2filters.setLanguage('en_US'); 
3filters.setPublishStatus('Online'); 
4filters.setChannel('app'); 
5
6Search.SuggestionOption options = new Search.SuggestionOption(); 
7options.setFilter(filters); 
8
9Search.SuggestionResults suggestionResults = Search.suggest('all', 'KnowledgeArticleVersion', options); 
10
11for (Search.SuggestionResult searchResult : suggestionResults.getSuggestionResults()) {     
12  KnowledgeArticleVersion article = (KnowledgeArticleVersion)searchResult.getSObject();   
13  System.debug(article.title); 
14}

setLimit(limit)

The maximum number of record or article suggestions to retrieve.

Signature

public void setLimit(Integer limit)

Parameters

  • limit: Type: Integer The maximum number of record or article suggestions to retrieve.

Return Value

Type: void

Usage

By default, the System.Search.suggest(String, String, Search.SuggestionOption) method returns the 5 most relevant results. However, if your query is broad, it could match more than 5 results. If Search.SuggestionResults.hasMoreResults() returns true, there are more than 5 results. To retrieve them, call setLimit(Integer) to increase the number of suggestions results.
1Search.SuggestionOption option = new Search.SuggestionOption();
2option.setLimit(10);
3Search.suggest('my query', 'mySObjectType', option);