Newer Version Available
Answers Class
Represents zone answers.
Namespace
Usage
Answers is a feature of the Community application that enables users to ask questions and have community members post replies. Community members can then vote on the helpfulness of each reply, and the person who asked the question can mark one reply as the best answer.
For more information on answers, see “Answers Overview” in the Salesforce online help.
Example
The
following example finds questions in an internal zone that
have similar titles as a new question:
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public class FindSimilarQuestionController {
18
19 public static void test() {
20 // Instantiate a new question
21 Question question = new Question ();
22
23 // Specify a title for the new question
24 question.title = 'How much vacation time do full-time employees get?';
25
26 // Specify the communityID (INTERNAL_COMMUNITY) in which to find similar questions.
27 Community community = [ SELECT Id FROM Community WHERE Name = 'INTERNAL_COMMUNITY' ];
28
29 question.communityId = community.id;
30
31 ID[] results = Answers.findSimilar(question);
32 }
33}
34The following example marks a reply as the best
reply:
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17ID questionId = [SELECT Id FROM Question WHERE Title = 'Testing setBestReplyId' LIMIT 1].Id;
18ID replyID = [SELECT Id FROM Reply WHERE QuestionId = :questionId LIMIT 1].Id;
19Answers.setBestReply(questionId,replyId);
20Answers Methods
The following are methods for Answers. All methods are static.
findSimilar(yourQuestion)
Returns a list of similar questions based on the title
of the specified question.
Signature
public static ID[] findSimilar(Question yourQuestion)
Parameters
- yourQuestion
- Type: Question
Return Value
Type: ID[]
Usage
Each findSimilar call counts against the SOSL statements governor limit allowed for the process.
setBestReply(questionId, replyId)
Sets the specified reply for the specified question as
the best reply. Because a question can have multiple replies, setting
the best reply helps users quickly identify the reply that contains
the most helpful information.
Signature
public static Void setBestReply(String questionId, String replyId)
Return Value
Type: Void