function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Curt RogersCurt Rogers 

How to Access a Knowledge Article using a LWC

My Goal:
I want to display a Knowledge Article selected from the Trending Articles list on the Home page or the Article Detail page in the Help Center Communities template.

The reason for this is that there is no simple way to display only the desired fields for a Knowledge Article. The Page Layout limitations causes undesirable fields to be display in the communities site (as many others attest with the same issue).

A Lightning Web Component will give me the control I am looking for, so I can display only the standard and custom fields I want to see.

Given this:
I understand that the Knowledge__kav object will let me access meta-data, while the KnowledgeArticleVersion object will allow me to get the Published Version object field data. I don't know how to access these together in an LWC. I have almost been able to do this using aan Apex class that returns the results of a SOQL query, but I only get the same record over an over again - its not reactive.

Realizing the Knowledge object is a strange animal, How can I achieve the above goal using a Lightning Web Component? I'm looking for the best practice for achieving my goal above?

Has anyone else done this using a LWC?

If someone can provide guidance on this, it would be most helpful.

There is no documentation or examples regarding the use of LWC to access the Knowledge object. All of them are simple Accounts or Contacts, and these standard objects do not work the same way as Knowledge objects.

I have been able to achieve (sort of) the above with an Aura component, but I feel like I should be able to do this with LWC.

In my prior attempts, I can use LWC code for Accounts or Contacts sucessfully, but whe n modified for Knowledge, it displays nothing.  I'm working with Salesforce support, but even they appear to be stymied by this.

Cna anyone provide some guidance?
Patrick Faucher 6Patrick Faucher 6
I have the same problem... I can't access Knowledge article in my LWC. In my case, I have selected an article but I can't figure out the way to get it in the controller. Article don't use recordId, they use urlName as mentionned here : 
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_page_reference_type

@api urlName; return nothing... 

 
Curt RogersCurt Rogers

Patrick,

I have (somewhat) successfully done this with an Aura component, but I am really looking for the best practice as an LWC @wire or @api.  My Aura solution only showed the article, but not the proper version. I abandoned this approach in favor of going with an LWC - just becuase I want all comonents to use LWC for our own consistency and documentation.

I have opened a case with support. The object model for Knowledge is a bit more complex than other objects.  There is a Knoweldge Article and a Artile Version, which is what you are actually trying to get to.

Salesforce Dev Support has mentioned that there is a whitelist that needs to be enabled to allow LWC access to Knowledge Article/Article Versions.  So, it could be "part" of the issue.

I am still working with them on this and will post my findings as I get towards a solution with them.

Here are some other helpful links for you.  You might see something I (or Salesforce) did not:

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_guidelines_knowledge.htm (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_guidelines_knowledge.htm" style="font-style:normal; font-variant-caps:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; -webkit-text-size-adjust:auto; -webkit-text-stroke-width:0px; font-family:Helvetica; font-size:12px)
https://dreamevent.secure.force.com/articleView?id=knowledge_lightning_limitations.htm&type=0 (https://dreamevent.secure.force.com/articleView?id=knowledge_lightning_limitations.htm&type=0)
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.data_wire_service_about

GitHub code for a similar approach:

https://github.com/FabienHuot/KnowledgeSearch/blob/master/force-app/main/default/classes/knowledgeSearchController.cls

Manju NiranjulaaManju Niranjulaa
Any Update on this Thread? 
 
Anand Avinash DosapatiAnand Avinash Dosapati
@curt Rogers 

did you manage to figure it out finally? if yes could you provide me with some input? As I am about to start implementing similar.

Thanks