For most internal pages (behind authentication) within a community, if you attempt to hit the page unauthenticated, you are prompted to authenticate and then redirected to the page your were attempting to access. For some reason however, Knowledge does not work that way. If you attempt to access a Knowledge article that requires authentication and that is not exposed to the Public Knowledge Base, you receive a 404 and not a login prompt. If you wanted to create an IdeaExchange idea around this, I think it's a good one.
Therefore the only way to accomplish this is with your own creative workaround. You'll want to create a Visualforce page that handles the unauthenticated redirect, call it KnowledgeRedirect or something. This page will need to be exposed via the communities Sites settings to unauthenticated users (via Public Access Settings for the VF page). The page would accept a querystring parameter that is either the id or name of your knowledge article (some unique identifier). On hitting the page with that querystring param, you would first check to see if the user is authenticated. This should suffice in apex:
if (UserInfo.getUserType()=='Guest') {
//redirect to the login page with the querystring param on the startUrl or retUrl, I can't recall, one of those
} else {
//redirect to the knowledge article
}
USE CASE – Salesforce Case code: 16538643
Customer Community – Napili template
Requirement:
The client wants that the their community users should have access on the Knowledge base to all the articles, in all languages.
In particular, in our project the customer has a Knowledge base in languages (English UK,Italian). Where the default language of KB is English UK.
The User of the Community should see potentially all the articles in the KB independently on the language settings of the user.
Salesforce standard behaviour - Napili template
Knowledge Base languages (English UK, Italian), default language English UK. To explain the context and the limits that we found we show 3 use cases.
1) Examples user community with language English UK
The user can see all and only the articles in English UK.
The user can’t see articles that are only in Italian. If the user try to access them by URL manipulation, the system give invalid page.
2) Example user community with language Italian
The user can see all and only the articles in Italian, independently if the articles has an English UK version (English UK is the default language for the KB platform).
The Italian user, is not able to see the articles that are only in English UK. If try to reach them by URL manipulation, the system returns invalid page.
3) Example user community with language different from Itanlian or English UK, let say German.
The user can see all and only those articles that has a version in the English UK (the KB default language). If the user try to reach articles that are only in italian through URL manipulation, the system gives invalid page.
Differences – singular behaviour from our point of view
The community user with language German, can see KB articles that are not visible by the Italian one.
Considerations
The Community user, enabled to the capability to change its own language, can see potentially all the articles in the KB, but he needs to change language in order to see them all.
Objective of the customer
The objective is to bypass this filter of the community user language, and allow the user to access to all the KB articles.
We would give the access to the resources (articles) through the standard service that community use, that mean through the page of Napili dedicated to knowledge “Article detail” page, which give access to the resources through the URL path structure
[Community istance url]+”/”+[community name]+”/s/article/”+[article version id]+”/”+[article url]
Is this Objective reachable through the standard “Article detail” behaviour of the Napili/community capabilities?
Summary
In our project, we are getting stuck on the scenarios where the standard community, is giving invalid page.
Salesforce Feedback
Salesforce said that this is the standard behaviour, and the community is designed to show to the users all the articles of the language used by the community user, and if the user language of the community language is not configured in the Knowledge base, than the user will see the articles of the standard language of Knowledge Base.
If you want to realize the request of the customer, is required to find a workaround.
Our actions after the feedback
We are prociding to avoid to use the community page “article”, and we are going to use a customer object that will allow us to wrap Knowledge Base to the community using the page “detail”.
I hope this will help others that may have a similar limitation.
Best Answer
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.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:
This will return an output like so where you can see
upVoteCount
anddownVoteCount
:You can make this query per channel (notice the url request).
Reference
Pulling normalizedScore for Articles
It's under
KnowledgeArticleVoteStat
in theNormalizedScore
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.