Search Class
Namespace
Search Methods
The following are static methods for Search.
find(searchQuery)
Signature
public static Search.SearchResults find(String searchQuery)
Parameters
- searchQuery
- Type: String
- A SOSL query string.
Return Value
Type: Search.SearchResults
Usage
Use this method wherever a static SOSL query can be used, such as in regular assignment statements and for loops.
find(searchQuery, accessLevel)
Signature
public static Search.SearchResults find(String searchQuery, System.AccessLevel accessLevel)
Parameters
- searchQuery
- Type: String
- A SOSL query string.
- accessLevel
- Type: System.AccessLevel
- (Optional) The accessLevel parameter specifies whether the method runs in system mode (AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Return Value
Type: Search.SearchResults
Usage
Use this method wherever a static SOSL query can be used, such as in regular assignment statements and for loops.
query(query)
Signature
public static sObject[sObject[]] query(String query)
Parameters
- query
- Type: String
- A SOSL query string.
- To create a SOSL query that includes the WITH SNIPPET clause, use the Search.find(String searchQuery) method instead.
Usage
This method can be used wherever a static SOSL query can be used, such as in regular assignment statements and for loops.
For more information, see Dynamic SOSL.
query(query, accessLevel)
Signature
public static List<List<SObject>> query(String query, System.AccessLevel accessLevel)
Parameters
- query
- Type: String
- A SOSL query string.
- To create a SOSL query that includes the WITH SNIPPET clause, use the Search.find(String searchQuery) method instead.
- accessLevel
- Type: System.AccessLevel
- (Optional) The accessLevel parameter specifies whether the method runs in system mode (AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Usage
This method can be used wherever a static SOSL query can be used, such as in regular assignment statements and for loops.
For more information, see Dynamic SOSL.
suggest(searchQuery, sObjectType, suggestions)
Signature
public static Search.SuggestionResults suggest(String searchQuery, String sObjectType, Search.SuggestionOption suggestions)
Parameters
- searchQuery
- Type: String
- A SOSL query string.
- sObjectType
- Type: String
- An sObject type.
- options
- Type: Search.SuggestionOption
- This object contains options that change the suggestion results.
- If the searchQuery returns KnowledgeArticleVersion objects, pass an options parameter with a Search.SuggestionOption object that contains a language KnowledgeSuggestionFilter and a publish status KnowledgeSuggestionFilter.
- For suggestions for all other record types, the only supported option is a limit, which sets the maximum number of suggestions returned.
Return Value
Type: SuggestionResults
Usage
- Suggestions for Salesforce Knowledge articles (KnowledgeArticleVersion)
- Salesforce Knowledge must be enabled in your organization. The user must have the “View Articles” permission enabled.
- The articles suggested include only the articles the user can access, based on the data categories and article types the user has permissions to view.
- Suggestions for other record types
- The records suggested include only the records the user can access.
- This method returns a record if its name field starts with the text in the search string. This method automatically appends an asterisk wildcard (*) at the end of the search string. Records that contain the search string within a word aren’t considered a match.
- Records are suggested if the entire search string is found in the record name, in the same order as specified in the search string. For example, the text string national u is treated as national u* and returns “National Utility” and “National Urban Company” but not “National Company Utility” or “Urban National Company”.
suggest(searchQuery, sObjectType, suggestions, accessLevel)
Signature
public static Search.SuggestionResults suggest(String searchQuery, String sObjectType, Search.SuggestionOption suggestions, System.AccessLevel accessLevel)
Parameters
- searchQuery
- Type: String
- A SOSL query string.
- sObjectType
- Type: String
- An sObject type.
- suggestions
- Type: Search.SuggestionOption
- This object contains options that change the suggestion results.
- If the searchQuery returns KnowledgeArticleVersion objects, pass an options parameter with a Search.SuggestionOption object that contains a language KnowledgeSuggestionFilter and a publish status KnowledgeSuggestionFilter.
- For suggestions for all other record types, the only supported option is a limit, which sets the maximum number of suggestions returned.
- accessLevel
- Type: System.AccessLevel
- (Optional) The accessLevel parameter specifies whether the method runs in system mode (AccessLevel.SYSTEM_MODE) or user mode (AccessLevel.USER_MODE). In system mode, the object and field-level permissions of the current user are ignored, and the record sharing rules are controlled by the class sharing keywords. In user mode, the object permissions, field-level security, and sharing rules of the current user are enforced. User mode is the default.
Return Value
Type: SuggestionResults
Usage
- Suggestions for Salesforce Knowledge articles (KnowledgeArticleVersion)
- Salesforce Knowledge must be enabled in your organization. The user must have the “View Articles” permission enabled.
- The articles suggested include only the articles the user can access, based on the data categories and article types the user has permissions to view.
- Suggestions for other record types
- The records suggested include only the records the user can access.
- This method returns a record if its name field starts with the text in the search string. This method automatically appends an asterisk wildcard (*) at the end of the search string. Records that contain the search string within a word aren’t considered a match.
- Records are suggested if the entire search string is found in the record name, in the same order as specified in the search string. For example, the text string national u is treated as national u* and returns “National Utility” and “National Urban Company” but not “National Company Utility” or “Urban National Company”.