Newer Version Available

This content describes an older version of this product. View Latest

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.

Syntax

URI
vXX.X/search/suggestions?q=search_string&sobject=object_types
Available since release
32.0
Formats
JSON, XML
HTTP methods
GET
Authentication
Authorization: Bearer token
Request body
None required
Request parameters
Parameter Description
fields Optional. Used for creating lookup queries. Specify multiple fields using a comma-separated list. Specifies which lookup fields to be returned in the response.
groupId Optional. Specifies one or more unique identifiers of one or more groups that the question to return was posted to. Specify multiple groups using a comma-separated list. This parameter is only applicable when the parameter type equals question. Don’t use with the userId.
ignoreUnsupportedSObjects Optional. Specifies what to do if unsupported objects are included in the request. If false and an unsupported object is included, an error is returned. If true and an unsupported object is included, the object is ignored and no error is returned. See the Unsupported Objects section for reference. The default is false.
limit Optional. Specifies the maximum number of suggested records to return. If a limit isn’t specified, 5 records are returned by default. If there are more suggested records than the limit specified, the response body’s hasMoreResults property is true.
networkId Optional. Specifies one or more unique identifiers for the community(ies) that the question to return is associated to. Specify multiple communities using a comma-separated list. This parameter is only applicable when the parameter type equals question or parameter sobject equals user.
q Required. The user’s search query string, properly URL-encoded. Suggestions are returned only if the user’s query string meets the minimum length requirements: one character for queries in Chinese, Japanese, Korean, and Thai; three characters for all other languages. Query strings that exceed the maximum length of 255 characters (or 200 consecutive characters without a space break) return an error.
sobject Required. The objects that the search is scoped to, such as Account or offer__c.

If the sobject value is feedItem, it is required to have the type parameter with a value of question.

Specify up to 10 objects with a comma-separated list. For example: sobject=Account,Contact,Lead. To take advantage of this feature, activate the CrossObjectTypeahead permission.

To specify the specific fields to return by object, use the following syntax with multiple fields in a comma-separated list. The sobject is lowercase.
1sobject=sobject.fields=fields

For example:

1&sobject=Account,Contact,Lead&account.fields=Website,Phone
2&contact.fields=Phone
topicId Optional. Specifies the unique identifier of the single topic that the question to return was tagged as. This parameter is only applicable when the parameter type equals question.
type Required when the sobject value is feedItem. Including this parameter for all other sobject values doesn’t affect the query. Specifies that the type of Feed is questions. Valid value: question.
userId Optional. Specifies one or more unique identifiers of one or more users who authored the question to return. Specify multiple users using a comma-separated list. This parameter is only applicable when the parameter type equals question. Don’t use with the groupId.
useSearchScope Optional. Available in API version 40.0 and later. The default value is false. If false, the objects specified in the request are used to suggest records. If true, in addition to the objects specified in the request, the user's search scope is used to suggest records. The search scope is the list of objects a user uses most frequently.
  • If the request doesn’t specify an object, use useSearchScope=true.
  • If useSearchScope=true and the user's search scope is empty, the default search scope is used to suggest records.
  • Only the first 10 objects are used to suggest records.
  • Objects specified in the sobject parameter are prioritized over objects in the user's search scope.
  • Values for the ignoreUnsupportedSObjects parameter aren’t applied to the objects in the search scope.
This example uses only the search scope.
1.../search/suggestions?q=Acme&useSearchScope=true
This example uses the search scope and the Account object.
1.../search/suggestions?q=Acme&sobject=Account&useSearchScope=true
where Optional. A filter that follows the same syntax as the SOQL WHERE clause. URL encode the expression.

Use the clause for an object, or globally for all compatible objects. An example of an object-specific clause is: account.where=name%20LIKE%20%27Smith%25%27. An example of a global clause is: where=name%20LIKE%20%27Smith%25%27. The parameter must be lower case. Any object-specific where clauses overrides the global where clause. You can’t use this parameter for the Question object.

To specify multiple entities, see the following example. This feature is available in version 38.0 and later.

1...search/suggestions?q=Smith 
2&sobject=Account,Contact,KnowledgeArticleVersion,CollaborationGroup,Topic,FeedItem 
3// Specifies a global where clause (to filter Account and Contact)
4&where=name%20LIKE%20%27Smith%25%27 
5// Overrides the global where clause for Knowledge Article (filtering by PublishStatus and Language is required for KnowledgeArticle)
6&knowledgearticleversion.where=PublishStatus='online'+and+language='en_US'
7// Overrides the global where clause for Topic
8&topic.where=networkid=<1234567891> 
9// Overrides the global where clause for CollaborationGroup
10&collaborationgroup.where=networkid=<1234567891> 
11// FeedItem-Question doesn't support where clauses, but we can filter the type and networkId
12&type=question 
13&networkId==<1234567891>

Usage

The suggestions resource returns records when the record’s name field includes the exact text in the search string. The last term in the search string can match the beginning of a word. Records that contain the search string within a word aren’t considered a match.

If the user’s search query contains quotation marks or wildcards, those symbols are automatically removed from the query string in the URI.

Note

Example

The text string national u is treated as national u* and returns “National Utility”, “National Urban Company”, and “First National University”.

Suggested Records Response

The suggestions resource returns display-ready data about likely relevant records that the user can access.

The order of results is determined by a relevance algorithm.

Each suggested record in the results contains these elements:
Element Description
Attributes The record’s object type and the URL for accessing the record.

Also includes the requested lookup fields’ values. For example, if you requested fields=Id,Name, the result would include the ID and name.

Name (or Title) The record’s Name field. In the absence of a standard Name field, the Title field is used for these objects:
  • Dashboard
  • Idea
  • IdeaTheme
  • Note
  • Question
In the absence of a standard Name or Title field, the main identifying field is used. For example, in cases, the Case Number is used.
Id The record’s unique identifier.

Example JSON Response Body

1[ {
2  "attributes" : {
3    "type" : "Account",
4    "url" : "/services/data/v32.0/sobjects/Account/001xx000003DH6WAAW"
5  },
6  "Id" : "001xx000003DH6WAAW"
7  "Name" : "National Utility Service"
8}, { 
9{
10  "attributes" : {
11    "type" : "Account",
12    "url" : "/services/data/v32.0/sobjects/Account/001xx000003DHJ4AAO"
13  },
14  "Id" : "001xx000003DHJ4AAO"
15  "Name" : "National Utility Service"
16}, {
17{
18  "attributes" : {
19    "type" : "Account",
20    "url" : "/services/data/v32.0/sobjects/Account/001xx000003DHscAAG"
21  },
22  "Id" : "001xx000003DHscAAG"
23  "Name" : "National Urban Technology Center"
24} ]

Example JSON Response Body for a Multiple Object Request

1[ {
2  "attributes" : {
3    "type" : "Account",
4    "url" : "/services/data/v38.0/sobjects/Account/001xx000003DMEKAA4"
5  },
6  "Id" : "001xx000003DMEKAA4"
7  "Name" : "Joe Doe Printing"
8}, { 
9{
10  "attributes" : {
11    "type" : "Account",
12    "url" : "/services/data/v38.0/sobjects/Account/001xx000003DLjvAAG"
13  },
14  "Id" : "001xx000003DLjvAAGO"
15  "Name" : "Joe Doe Plumbing"
16}, {
17{
18  "attributes" : {
19    "type" : "Contact",
20    "url" : "/services/data/v38.0/sobjects/Contact/003xx000004U9Y9AAK"
21  },
22  "Id" : "003xx000004U9Y9AAK"
23  "Name" : "John Doe"
24} ]

Example XML Response Body

1<?xml version=”1.0” encoding=”UTF-8”?
2<suggestions>
3  <autoSuggestResults type="Account" url="/services/data/v32.0/sobjects/Account/001xx000003DH6WAAW">  
4    <Id>001xx000003DH6WAAW</Id>
5    <Name>National Utility Service</Name>
6  </autoSuggestResults>
7  <autoSuggestResults type="Account" url="/services/data/v32.0/sobjects/Account/001xx000003DHJ4AAO">
8    <Id>001xx000003DHJ4AAO</Id>
9    <Name>National Utility Service</Name>
10  </autoSuggestResults> 
11  <autoSuggestResults type="Account" url="/services/data/v32.0/sobjects/Account/001xx000003DHscAAG"> 
12    <Id>001xx000003DHscAAG</Id> 
13    <Name>National Urban Technology Center</Name>
14  </autoSuggestResults>
15  <hasMoreResults>true</hasMoreResults> 
16</suggestions>

Unsupported Objects

The suggestions resource supports all searchable objects except the following.
  • ContentNote
  • Event
  • External objects
  • FeedComment
  • FeedPost
  • IdeaComment
  • Pricebook2
  • Reply
  • TagDefinition
  • Task