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
MonaliDMonaliD 

How to get article type in apex?

hi,

 

I am retriving article type of a particular article using getGlobalDescribe and keyPrefix.

But is there any other way to get article type ?

 

Thanks,

Monali

 

francoisLfrancoisL

Hi,

 

No, there is no other way to retrieve the article type.

StephenDavidsonStephenDavidson

MonaliD:

Any chance you could share your code for finding out ArticleType?

 

Thanks!

MonaliDMonaliD

Hi StephenDavidson,

 

Here is code for getting article type.


        Map<String, Schema.SObjectType> objectMap = Schema.getGlobalDescribe();
        Map<String, String>keyPrefixMap = new Map<String, String>{};
        Set<String> keyPrefixSet = objectMap.keySet();
        for(String sObj : keyPrefixSet)
        {
            Schema.DescribeSObjectResult r = objectMap.get(sObj).getDescribe();
            String tempName = r.getName();  //will store object name
            String tempPrefix = r.getKeyPrefix(); //will store object prefix
            keyPrefixMap.put(tempPrefix, tempName); //e.g map will contain ('001','Account') for account object
            
        }

       

        string articleId = '0039000000A6bUw';

        String articleIdPrefix = articleId.subString(0,3);
        String objectType = keyPrefixMap.get(articleIdPrefix); 
       

      

StephenDavidsonStephenDavidson

Thank you kindly.

 

I also got the following from Francois to be used with spring 2012 release. 

 

    if (article instanceof troubleshootingobj__kav){
// do troubleshooting article specific field assignments.
}