[SalesForce] Add Knowledge Article Rating entry with Apex

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.

Thanks!

Best Answer

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

Related Topic