Salesforce Sites have the capability of giving access to Knowledge in your Salesforce org. Users with Customer Community licenses can view the Knowledge articles through a site. Depending on which channel is used to display the article, the article view count increments accordingly.
When a Customer Community-related license user views an article on a site, the article view count is counted towards the customer channel. When an internal user views the article, the count increments against the Internal App channel.
See Articles Overview.
However, in scenarios where a controller class runs a SOQL (Structured Query Language) query to retrieve and display an article, the article view count is not automatically updated. This is because the standard view count increment requires the article to be accessed through the standard display mechanism. When custom code is used to retrieve the article via SOQL, the standard API call that updates the view count is not triggered.
To ensure that article view counts are tracked correctly when articles are retrieved via custom SOQL queries on Sites, add the UPDATE VIEWSTAT clause to your SOQL query. This instructs Salesforce to increment the view count for the article when the query executes, replicating the behavior of the standard channel display.
Your SOQL query should include the relevant article fields (such as id, KnowledgeArticleId, and Title), filter by PublishStatus='online', the appropriate Language, and the specific KnowledgeArticleVersion, and then append UPDATE VIEWSTAT at the end of the query.
A sample would look like this:
SELECT id, KnowledgeArticleId, Title FROM FAQ__kav WHERE PublishStatus='online' and Language = 'en_US' and KnowledgeArticleVersion = 'kaxxxxxxxxxxxxx' UPDATE VIEWSTAT
For example, a query on a custom article type object (such as FAQ__kav) would retrieve the article record and simultaneously update its view count for the customer channel. Without this clause, the view count remains unchanged even when the article is displayed to the end user.
000386899

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.