Fetch Data Category Selections for Salesforce Knowledge Article

Fetch Data Category Selections for Salesforce Knowledge Article

The Unseen Challenge: Data Categories and Multilingual Salesforce Knowledge

Salesforce Knowledge is a powerful tool for building comprehensive knowledge bases, empowering users and customers with quick access to information. For global organizations, translating knowledge articles is crucial to serve diverse audiences. However, a common pitfall often goes unnoticed: Data Category Selections are not automatically inherited or linked to translated versions of Knowledge Articles.

This can lead to a fragmented user experience, where a translated article might be discoverable through search but lack the crucial categorization that helps users browse and filter information effectively. From an SEO perspective, this means your translated articles might not be as discoverable or well-organized as their master language counterparts, potentially impacting user engagement and information retrieval.

Why Data Categories Matter for Your Knowledge Base

Data Categories are the backbone of a well-organized Salesforce Knowledge base. They allow you to:

  • Improve Discoverability: Users can easily navigate and filter articles based on relevant categories, leading to a better user experience.
  • Enhance Search Precision: Data categories can be used in search queries, helping users find exactly what they need faster.
  • Control Article Visibility: Data categories can be used with Data Category Visibility settings to control which users or profiles can see specific articles.
  • Boost SEO (Internal & External): A well-categorized knowledge base is inherently more organized, making it easier for both internal users and external search engines to understand the content’s context and relevance. This can indirectly improve your overall SEO by providing a better user experience and clear content hierarchy.

The Translation Disconnect: What Happens to Data Categories?

When you translate a Salesforce Knowledge Article, new Knowledge__kav records are created for each language. However, the associated Knowledge__DataCategorySelection records (which define the direct assignments of data categories) are not automatically replicated or linked to these translated versions. Instead, they remain tied to the master or original language article.

This means if a user is viewing a translated article, and your organization relies on data categories for navigation or filtering, that translated article might appear uncategorized, even if its master version is perfectly organized.

The Solution: Programmatically Fetching and Applying Data Categories

To ensure your translated Knowledge Articles maintain their data category associations, you need to programmatically fetch the data categories from the master language article and potentially associate them with the translated versions (depending on your specific use case and how you want to manage translated article categories).

Here’s an Apex code snippet that demonstrates how to retrieve the data categories for a Knowledge Article, whether it’s the master language or a translated version:

Apex Code:

List < Knowledge__DataCategorySelection > listDCS = new List < Knowledge__DataCategorySelection >();

// Assuming you have the Id of the Knowledge Article Version (kav) you are currently working with
// For demonstration, we use a sample Id. In a real scenario, this Id would come from your context.
Knowledge__kav objKAV = [
    SELECT Id, Title, Summary, ArticleNumber, PublishStatus,
    Language, IsMasterLanguage, MasterVersionId
	FROM Knowledge__kav
	WHERE Id = 'ka0Kj0000018YJtIAM' // Replace with your actual Knowledge Article Version Id
    LIMIT 1
];

if ( objKAV.IsMasterLanguage ) {

    // If it's the master language, directly query its data category selections
    listDCS = [
        SELECT Id, DataCategoryName, DataCategoryGroupName
        FROM Knowledge__DataCategorySelection
        WHERE ParentId =: objKAV.Id
    ];

} else {

    // If it's a translated article, fetch data categories from its master version
    listDCS = [
        SELECT Id, DataCategoryName, DataCategoryGroupName
        FROM Knowledge__DataCategorySelection
        WHERE ParentId =: objKAV.MasterVersionId
    ];

}

// For debugging or further processing
System.debug('Fetched Data Category Selections: ' + listDCS);

// Now 'listDCS' contains the data categories associated with either the master or the master's version
// You can then use this information to:
// 1. Display data categories on your custom knowledge article pages.
// 2. Programmatically create new Knowledge__DataCategorySelection records for the translated article (if desired).
// 3. Implement custom logic for filtering or searching based on these categories.

Code Explanation:

  1. Knowledge__kav Query: We first query the Knowledge__kav object using the ID of the specific Knowledge Article Version we’re interested in. We select key fields like IsMasterLanguage and MasterVersionId to determine its translation status.
  2. IsMasterLanguage Check:
    • If objKAV.IsMasterLanguage is true, it means we are dealing with the original language article. In this case, we directly query Knowledge__DataCategorySelection records where ParentId matches the Id of our current objKAV.
    • If objKAV.IsMasterLanguage is false, it’s a translated article. To get its data categories, we need to look at its MasterVersionId. We then query Knowledge__DataCategorySelection records where ParentId matches this MasterVersionId.
  3. listDCS: The listDCS variable will then contain the relevant Knowledge__DataCategorySelection records, giving you access to the DataCategoryName and DataCategoryGroupName.

Beyond Fetching: What to Do with the Data Categories?

Once you’ve retrieved the data categories using the above Apex code, you have several options depending on your specific needs:

  • Display on Custom Pages: If you’re using custom Visualforce pages, Aura components, or LWC components to display your Knowledge Articles, you can use this listDCS to dynamically render the relevant data categories for the translated article, ensuring a consistent user experience.
  • Re-associate Programmatically: In more advanced scenarios, you might choose to programmatically create new Knowledge__DataCategorySelection records for the translated article, effectively mirroring the master article’s categories. This would typically involve an Apex trigger or a batch process that runs after translations are published.
  • Custom Search & Filtering: You can leverage these fetched data categories in custom search interfaces or filtering mechanisms, allowing users to find translated articles based on categories that were originally assigned to the master version.

Conclusion

Maintaining data category consistency across all language versions of your Salesforce Knowledge Articles is vital for a seamless user experience and effective information governance. While Salesforce doesn’t automatically propagate data category selections to translated articles, the good news is that it’s a solvable problem through programmatic approaches using Apex. By implementing solutions like the one demonstrated, you can ensure your multilingual knowledge base remains well-organized, discoverable, and truly valuable to your global audience.

Call to Action:

  • Are you facing challenges with your multilingual Salesforce Knowledge base?
  • Need assistance with custom Salesforce development for your Knowledge implementation?

Contact us today to discuss how we can help you optimize your Salesforce Knowledge experience!

Leave a Reply