[SalesForce] How to find Knowledge Article Type

I am querying the KnowledgeArticleVersion table to list all articles in order to display a list of links to articles.

Because of some limitations I cannot use the <knowledge:articleList> tag.

I have these article types: Documentation__kav, FAQ__kav, Private_Article__kav.

Other article types will be added later.

How do I find out the article type from the KnowledgeArticleVersion table?

Maybe there are other tables I can query to find this out?

Best Answer

I found how to do it.

As @scyforce said I need to use the key prefix.

Link on Salesforce Community

Code from that page:

    // Create DescribeMap
    private void createDescribeMap() {
        Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
        Set<String> keySet = gd.keySet();
        for (String key : keySet) {
            Schema.SObjectType objectType = gd.get(key);
            if (key.endsWith('ka') || key.endsWith('kb')) {
                this.describeMap.put(objectType.getDescribe().getKeyPrefix(), objectType.getDescribe().getLabel());
            }
        }
    }

    //Util method to get Article Type from article Id.
    public String getArticleType(String articleId) {
        String articlePrefix = articleId.substring(0,3);
        Set<String> keySet = describeMap.keySet();
        String articleType = null;
        for(String key: keySet) {
            if(articlePrefix.equalsIgnoreCase(key)) {
                articleType = describeMap.get(key);
                return articleType;
            }
        }
        return articleType;
    }
Related Topic