Understand Salesforce Lightning Knowledge Data Model

by Sudipta Deb | Sep 17, 2020 | Article, Data Model, Knowledge Management, lightning | 8 comments

While working with Lightning Knowledge, what I realized is that there is hardly any tutorial/post which explains the Knowledge Data Model in a very simple way. So I thought of writing my understanding with examples covering the part of the data model. I hope this will help you to understand the data model clearly and quickly.

Understanding the data model is always very important while doing the development as it will help you to play with the objects and do configure/customization that is possible, basically getting the maximum benefit of the platform.
To start with, the Knowledge Object Model is based on Abstract and Concrete objects. 

Core Abstract and Concrete Objects

The core abstract objects are – KnowledgeArticle and KnowledgeArticleVersion. The corresponding concrete versions are – Knowledge__ka and Knowledge__kav.
Below is the data model from the Salesforce Developer Guide –

Complete Data Model 

Relationship between Knowledge__ka and Knowledge__kav

As per the data model, the relationship between Knowledge__ka and Knowledge__kav is 1 to many. That is one Knowlegde__ka can have multiple Knowledge__kav. The link is happening through KnowledgeArticleId (remember KnowledgeArtcileId and Id are two different fields). So let’s check the example below.
The “HelloWorld” article is having two versions – 

Now if I run the query against Knowledge__ka, I am getting one entry which provides me the KnowledgeArticleId

Now with the same KnowledgeArticleId, if I query Knowledge__kav, I will get one entry. Surprised?? Why only one entry where it should be two. The reason is that when you publish version 2, version 1 is marked as Archived. So SOQL query will not count the archived versions.

If I create another version and mark that as Draft (not publish), then the query will return two entries like below –

Note – Here is the link –

Knowledge__ka.Id = Knowledge__kav.KnowledgeArticleId

Relationship between Knowledge__kav and Knowledge__DataCategorySelection

Here is the same above document with two DataCategory – India and Canada

Note – Here is the link –

Knowledge__kav.Id = Knowledge__DataCategorySelection.ParentId

Relationship between Knowledge__ka and Knowledge__ViewStat

Knowledge__ViewStat is derived from abstract object KnowledgeArticleViewStat. It is used to store the number of views for a specific article.
The link is –

Knowledge__ka.Id = Knowledge__ViewStat.ParentId

Here is the query 

Relationship between Knowledge__ka and Vote

The object is used to store information about Upvote and Downvote against the article.
The link is –

Knowledge__ka.Id = Vote.ParentId

Here is the query 

I hope this will help you to understand the data model. Please let me know your feedbacks. Thanks.

Written by

Related Posts

Difference Between WhoId and WhatId in Salesforce

Difference Between WhoId and WhatId in Salesforce

In the realm of Salesforce, understanding the intricacies of its data model is crucial for effective customization and utilization of the platform’s functionalities. Among the nuances lies the concept of polymorphic fields, particularly evident in the Event and Task objects through the whoid and whatid fields. These fields play a pivotal role in associating records with various objects, enabling flexibility and efficiency in managing sales and customer interactions. In this blog post, I will delve into the disparities between whoid and whatid, shed light on their polymorphic nature, and provide examples of SOQL queries to leverage their capabilities.

read more...

Kitchener Canada Developer Group Event: Shadow DOM, CSS and Styling Hooks in LWC by Alba Rivas

Special thanks to our speaker, Alba Rivas, for the session on “Shadow DOM, CSS and Styling Hooks in LWC“. Presentation: Shadow DOM, CSS and Styling Hooks in LWC what you need to know from Sudipta Deb ☁ Recording: Reference Links: SLDS Design Tokens Github...

read more...

8 Comments

  1. Denver Doug

    Thanks for sharing Sudipta! Very helpful

    Reply
  2. Denver Doug

    Thanks for sharing Sudipta! Very helpful

    Reply
  3. Sudipta Deb

    Thank you Denver for your comment

    Reply
  4. Yusuf

    This is really useful. The Knowledge data model is complex but you did a great job in explaining it.

    Reply
  5. Sudipta Deb

    Thank you Yusuf for your comment.

    Reply
  6. Unknown

    Hi Sudipta

    Need your suggestion on to update publish articles of 37k volume to Draft , and then need to do update of a custom field from Data Loader and then again update those to Publish status.With Dataloader, I can do the 2 and 3 steps. But the first step to change to draft, I am not aware of this. Any method of Batch Apex with similar example code exists, Please share.

    Thanks in Advance!
    Nalini
    srinalini.ch@gmail.com

    Reply
  7. user369

    Hi, I want to create report on “Knowledge Article views” that should be grouped by “Knowledge Data category”. Please help me on this

    Reply
    • Sudipta Deb

      Can you please try joining the article views with categories?

      Reply

Leave a Reply