QuestionAndAnswers Class

Access question and answers suggestions.

Namespace

ConnectApi

QuestionAndAnswers Methods

The following are methods for QuestionAndAnswers. All methods are static.

getSuggestions(communityId, q, subjectId, includeArticles, maxResults)

Returns question and answers suggestions.

API Version

32.0

Requires Chatter

No

Signature

public static ConnectApi.QuestionAndAnswersSuggestions getSuggestions(String communityId, String q, String subjectId, Boolean includeArticles, Integer maxResults)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.
subjectId
Type: String
Specify a subject ID to search only questions on that object. If the ID is a topic or a user, the ID is ignored.
includeArticles
Type: Boolean
Specify true to include knowledge articles in the search results. To return only questions, specify false.
maxResults
Type: Integer
The maximum number of results to return for each type of item. Possible values are 1–10. The default value is 5.

Usage

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.

setTestGetSuggestions(communityId, q, subjectId, includeArticles, maxResults, result)

Registers a ConnectApi.QuestionAndAnswersSuggestions object to be returned when getSuggestions is called with matching parameters in a test context. You must use the method with the same parameters or the code throws an exception.

API Version

32.0

Signature

public static Void setTestGetSuggestions(String communityId, String q, String subjectId, Boolean includeArticles, Integer maxResults, ConnectApi.QuestionAndAnswersSuggestions result)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
q
Type: String
Required and cannot be null. Specifies the string to search. The search string must contain at least two characters, not including wildcards. See Wildcards.
subjectId
Type: String
Specify a subject ID to search only questions on that object. If the ID is a topic or a user, the ID is ignored.
includeArticles
Type: Boolean
Specify true to include knowledge articles in the search results. To return only questions, specify false.
maxResults
Type: Integer
The maximum number of results to return for each type of item. Possible values are 1–10. The default value is 5.
result
Type: ConnectApi.QuestionAndAnswersSuggestions
The object containing test data.

Return Value

Type: Void

updateQuestionAndAnswers(communityId, feedElementId, questionAndAnswersCapability)

Choose or change the best answer for a question.

API Version

32.0

Requires Chatter

Yes

Signature

public static ConnectApi.QuestionAndAnswersCapability updateQuestionAndAnswers(String communityId, String feedElementId, ConnectApi.QuestionAndAnswersCapabilityInput questionAndAnswersCapability)

Parameters

communityId
Type: String
Use either the ID for a community, internal, or null.
feedElementId
Type: String
The ID for a feed element.
questionAndAnswersCapability
Type: ConnectApi.​QuestionAndAnswers​CapabilityInput
Specify the best answer (comment ID) for the question.

Return Value

Type: ConnectApi.QuestionAndAnswersCapability

If the feed element doesn’t support this capability, the return value is ConnectApi.NotFoundException.

Example

ConnectApi.QuestionAndAnswersCapabilityInput qaInput = new ConnectApi.QuestionAndAnswersCapabilityInput();
qaInput.bestAnswerId = '0D7D00000000lMAKAY';

ConnectApi.QuestionAndAnswersCapability qa = ConnectApi.QuestionAndAnswers.updateQuestionAndAnswers(null, '0D5D0000000XZjJ', qaInput);