does anybody know whether it is possible to add new rating entries to Knowledge articles with Apex code?

If yes, how would that code look like? I found some information on how to read the KnowledgeArticleVoteStat object for a given KB article with SOQL, which has the NormalizedScore attribute available.

But I am not sure, how to work with that information.

Would appreciate any help.


1 Answer 1


If you have a look at the entity relationship diagram (ERD) which illustrates relationships between the Salesforce Knowledge objects, you will see that the Vote object is related with the KnowledgeArticle. So to create a rating with Apex, you will simply have to create a new record of VOTE sObject and set the parentId as the KnowledgeArticleId and the Type as the rating score i.e. 1,2,3,4 or 5.

One important thing that you need to keep in mind while creating votes through APEX is that each user can rate an article only once. If you attempt to rate the same article again by the same user then an exception would be thrown as APEX would not allow duplicate vote entries by the same user for the same article

  • well, the same user cannot rate the article more than once :), if the same article is rated then it has to be run only once for each user. Commented Apr 26, 2015 at 10:16
  • I would like to add that for thumbs up/thumbs down that replaced stars this is exactly the same object: for thumb down the type = 1, for thumb up the type = 5
    – neff
    Commented Aug 21, 2019 at 9:35

You must log in to answer this question.

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