Search Class

Search objects using keywords or a natural language query.

ConnectApi

These methods are for Search. All methods are static.

Search objects using a natural language query and return an answer.

63.0

63.0

No

public static ConnectApi.SearchAnswer answer(String q)

q

Type: String

Natural language query to search for in the org.

Type: ConnectApi.SearchAnswer

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

Search an object using a natural language query and return an answer.

63.0

63.0

No

public static ConnectApi.SearchAnswer answer(String q, String objectApiName)

q

Type: String

Natural language query to search for in the org.

objectApiName

Type: String

API name of the object.

Type: ConnectApi.SearchAnswer

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

Search an object using a natural language query and display fields.

63.0

63.0

No

public static ConnectApi.SearchAnswer answer(String q, String objectApiName, List<String> displayFields)

q

Type: String

Natural language query to search for in the org.

objectApiName

Type: String

API name of the object.

displayFields

Type: List<String>

List of fields to display and return in the search answer. The default is the citation field.

Type: ConnectApi.SearchAnswer

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

Search objects using keyword search and return result groups.

63.0

63.0

No

public static ConnectApi.SearchResultGroups findAndGroup(String q)

q

Type: String

One or more keywords to search for in the org.

Type: ConnectApi.SearchResultGroups

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

Search objects using keyword search and a configuration. The search returns result groups.

63.0

63.0

No

public static ConnectApi.SearchResultGroups findAndGroup(String q, String configurationName)

q

Type: String

One or more keywords to search for in the org.

configurationName

Type: String

Search configuration to apply.

Type: ConnectApi.SearchResultGroups

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

Search objects using keyword search, a configuration, and highlights. The search returns result groups.

63.0

63.0

No

public static ConnectApi.SearchResultGroups findAndGroup(String q, String configurationName, Boolean highlights)

q

Type: String

One or more keywords to search for in the org.

configurationName

Type: String

Search configuration to apply.

highlights

Type: Boolean

Specifies whether search generates a text highlight (true) or not (false).

Type: ConnectApi.SearchResultGroups

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

Search an object using keywords and return results.

63.0

63.0

No

public static ConnectApi.ScopedSearchResults find(String objectApiName, ConnectApi.SearchRequest request)

objectApiName

Type: String

API name of the object to search.

request

Type: ConnectApi.SearchRequest

ConnectApi.SearchRequest input class with more information about what and how to search.

Type: ConnectApi.ScopedSearchResults

To test code that uses this method, use the matching set test method (prefix the method name with setTest). Use the set test method with the same parameters or the code throws an exception.

These test methods are for Search. All methods are static.

For information about using these methods to test your ConnectApi code, see Testing ConnectApi Code.

Registers a ConnectApi.SearchAnswer object to be returned when the matching answer(q) method is called in a test context. Use the method with the same parameters or you receive an exception.

63.0

public static Void setTestAnswer(String q, ConnectApi.SearchAnswer result)

q

Type: String

Natural language query to search for in the org.

result

Type: ConnectApi.SearchAnswer

Object containing test data.

Type: Void

Registers a ConnectApi.SearchAnswer object to be returned when the matching answer(q, objectApiName) method is called in a test context. Use the method with the same parameters or you receive an exception.

63.0

public static Void setTestAnswer(String q, String objectApiName, ConnectApi.SearchAnswer result)

q

Type: String

Natural language query to search for in the org.

objectApiName

Type: String

API name of the object.

result

Type: ConnectApi.SearchAnswer

Object containing test data.

Type: Void

Registers a ConnectApi.SearchAnswer object to be returned when the matching answer(q, objectApiName, displayFields) method is called in a test context. Use the method with the same parameters or you receive an exception.

62.0

public static Void setTestAnswer(String q, String objectApiName, List<String> displayFields, ConnectApi.SearchAnswer result)

q

Type: String

Natural language query to search for in the org.

objectApiName

Type: String

API name of the object.

displayFields

Type: List<String>

List of fields to display and return in the search results. By default, the fields displayed are defined by the search layout.

result

Type: ConnectApi.SearchAnswer

Object containing test data.

Type: Void

Registers a ConnectApi.SearchResultGroups object to be returned when the matching findAndGroup(q) method is called in a test context. Use the method with the same parameters or you receive an exception.

63.0

public static Void setTestFindAndGroup(String q, ConnectApi.SearchResultGroups result)

q

Type: String

One or more keywords to search for in the org.

result

Type: ConnectApi.SearchResultGroups

Object containing test data.

Type: Void

Registers a ConnectApi.SearchResultGroups object to be returned when the matching findAndGroup(q, configurationName) method is called in a test context. Use the method with the same parameters or you receive an exception.

63.0

public static Void setTestFindAndGroup(String q, String configurationName, ConnectApi.SearchResultGroups result)

q

Type: String

One or more keywords to search for in the org.

configurationName

Type: String

Search configuration to apply.

result

Type: ConnectApi.SearchResultGroups

Object containing test data.

Type: Void

Registers a ConnectApi.SearchResultGroups object to be returned when the matching findAndGroup(q, configurationName, highlights) method is called in a test context. Use the method with the same parameters or you receive an exception.

63.0

public static Void setTestFindAndGroup(String q, String configurationName, Boolean highlights, ConnectApi.SearchResultGroups result)

q

Type: String

One or more keywords to search for in the org.

configurationName

Type: String

Search configuration to apply.

highlights

Type: Boolean

Specifies whether search generates a text highlight (true) or not (false).

result

Type: ConnectApi.SearchResultGroups

Object containing test data.

Type: Void

Registers a ConnectApi.ScopedSearchResults object to be returned when the matching find(objectApiName, request) method is called in a test context. Use the method with the same parameters or you receive an exception.

63.0

public static Void setTestFind(String objectApiName, ConnectApi.SearchRequest request, ConnectApi.ScopedSearchResults result)

objectApiName

Type: String

API name of the object to search.

request

Type: ConnectApi.SearchRequest

ConnectApi.SearchRequest input class with more information about what and how to search.

result

Type: ConnectApi.ScopedSearchResults

Object containing test data.

Type: Void