# How do Data Categories structure and secure Salesforce Knowledge articles?

**Topic:** Service Cloud · **Difficulty:** Medium · **Tags:** Service Cloud, Data Categories, Security

Read it on the site: https://www.forcechallenges.com/interview-questions/how-do-data-categories-structure-and-secure-salesforce-knowledge-articles

## Answer

**Basics:** A Data Category Group is a taxonomy (for example Product, Region, Audience). Within it, categories form a tree (Product > Laptops > Gaming). Authors tag each article with one or more categories per group. Agents and customers then filter by category when searching, and visibility rules limit what each user sees.

**How it works:** Setup > Data Categories > New Category Group (activate it for Knowledge), build the hierarchy, and optionally set the group on other objects. When authoring, choose categories in the article's category selector. Then set Data Category Visibility on roles, profiles or permission sets. In Lightning, the Knowledge component and Experience Cloud search apply those filters automatically. Common limits: up to five active groups, up to five levels deep, and 100 categories per group (verify current values).

**Advanced / deep dive:** Design the taxonomy around audience and product, not around org charts, because visibility maps to it. Keep it shallow: deep trees are hard to maintain and slower to reason about. Use separate groups for independent dimensions so visibility combines cleanly (user must see at least one category in each group where the article is categorized). Categories are metadata-like setup records, so deploy them through metadata (the DataCategoryGroup metadata type) and avoid renaming casually. Categories are assigned to articles through the `<ArticleType>__DataCategorySelection` object (for Lightning Knowledge, `Knowledge__DataCategorySelection`) which can be loaded with Data Loader. Search by category uses `WITH DATA CATEGORY`. Data categories also support reporting by topic, helping identify content gaps. Governance: assign a taxonomy owner, because ad hoc additions produce overlapping categories.

**Code / config example:**
```apex
// Tag a draft article with a category (bulk by lists in production)
insert new Knowledge__DataCategorySelection(
  ParentId = draftArticleVersionId,           // version Id of the draft
  DataCategoryGroupName = 'Product',
  DataCategoryName = 'Laptops'
);
```

**Hidden gotchas & must-remember points:**
- Category assignments belong to the article version, so re-tag when creating a new draft if they do not carry over (verify behavior).
- Category API names, not labels, are used in SOQL and Apex.
- A deactivated group stops filtering and visibility, so articles can suddenly appear or vanish.
- Categories do not replace channels; both must allow access.
- Retiring or moving a category can silently change user visibility.
- Hierarchy and count limits exist, so design before you build.

**Best practice:** Keep two or three well-defined groups (audience, product, topic) with a named owner, and manage them as deployable metadata.

---
Source: ForceChallenges · last updated 2026-11-02
