4

When we open any knowledge article in community then at the bottom we have an option like Was this article helpful? So when we click on like or dislike then on which object that count stores.

I want to create a custom lwc for article feedback so, I need to insert those voting records using apex. But don't know where does it stores.

2 Answers 2

4

I'll break this up as I answered a different couple things for inserting a vote in apex, pulling the vote stats for an article, and for getting a normalized score of the article votes.


Insert a vote record

There's a Vote object you'd need to interact with and set the ParentId to the knowledge article. The Knowledge Object Model below indicates this.

enter image description here

The Salesforce Knowledge Developer Guide is your friend here and you'll see the model I pasted above. It's important to note, based on this answer, that each user can rate an article only once.


Pulling the vote stats through REST API. Going again off the same developer guide, you can do the following:

/services/data/v38.0/support/knowledgeArticles?sort=ViewScore&channel=Pkb&pageSize=3
HTTP Headers:
Content-Type: application/json; charset=UTF-8
Accept: application/json
Accept-Language: en-US

This will return an output like so where you can see upVoteCount and downVoteCount:

{
"articles" : [ {
"articleNumber" : "000001002",
"categoryGroups" : [ ],
"downVoteCount" : 0,
"id" : "kA0xx000000000BCAQ",
"lastPublishedDate" : "2015-02-25T02:07:18Z",
"summary" : "With this online Chinese input tool, you can type Chinese characters
through your web browser without installing any Chinese input software in your system.
The Chinese online input tool uses the popular Pin Yin input method. It is a fast and
convenient tool to input Chinese on English OS environments.",
"title" : "Long text test",
"upVoteCount" : 0,
"url" : "/services/data/v38.0/support/knowledgeArticles/kA0xx000000000BCAQ",
"viewCount" : 4,
"viewScore" : 100.0
}, {
"articleNumber" : "000001004",
"categoryGroups" : [ ],
"downVoteCount" : 0,
"id" : "kA0xx000000000LCAQ",
"lastPublishedDate" : "2016-06-21T21:11:02Z",
"summary" : "The number of characters required for complete coverage of all these
languages' needs cannot fit in the 256-character code space of 8-bit character encodings,
requiring at least a 16-bit fixed width encoding or multi-byte variable-length encodings.
\r\n\r\nAlthough CJK encodings have common character sets, the encodings often used to
represent them have been developed separately by different East Asian governments and
software companies, and are mutually incompatible. Unicode has attempted, with some
controversy, to unify the character sets in a process known as Han unification.\r\n\r\nCJK
character encodings should consist minimally of Han characters p",
"title" : "Test Images",
"upVoteCount" : 0,
"url" : "/services/data/v38.0/support/knowledgeArticles/kA0xx000000000LCAQ",
"viewCount" : 0,
"viewScore" : 0.0
}, {
"articleNumber" : "000001012",
"categoryGroups" : [ ],
"downVoteCount" : 0,
"id" : "kA0xx000000006GCAQ",
"lastPublishedDate" : "2016-06-21T21:10:48Z",
"summary" : null,
"title" : "Test Draft 2",

You can make this query per channel (notice the url request).


Reference

Pulling normalizedScore for Articles

It's under KnowledgeArticleVoteStat in the NormalizedScore field. It's not the raw stats as it's a normalized score based on the # of thumbs up/down and when those votes were cast.

enter image description here

3
  • Thanks Kris for your reply. I want to create a custom lwc component for article feedback. So using apex I want to insert the vote record so using this object this is not possible. I can use this object to retrieve the overall average of voting. Can you let me know where do I store the voting information. Jan 9, 2020 at 14:20
  • I might have misunderstood your aim here. I've edited it to include the info you need to do what you asked and left the other info I had originally wrote up if it's of interest. Jan 9, 2020 at 14:43
  • As I am making lwc for article feedback which used by guest users on public community site but after reading your given reference information I come to know that we can insert only a record of vote for a user. So for guest user we cant insert more than one record. Anyways I'm now creating a custom object for storing vote info. Thanks for your valuable information. Jan 9, 2020 at 20:37
0

long story short, On Vote object, we have lookup relation to Knowledge_ka object, On Both Knowledge_kav, Knowledge_ka objects we have articleNumber field. So, to find the vote count,

  1. select id,ArticleNumber from Knowledge__kav where id='Knowledge__kav_Record_Id'

  2. select id,ArticleNumber from Knowledge__ka where ArticleNumber='ArticleNumber_we_got_in_above_query'

  3. select id,ParentId,Type from Vote where ParentId = 'Knowledge_ka_Record_Id_we_got_in_above_query'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .