0

I am working on KnowledgeArticleVersion and want to show the list of articles on Visual force page.

SObjectType objToken = Schema.getGlobalDescribe().get('KnowledgeArticleVersion');
DescribeSObjectResult objDef = objToken.getDescribe();
Map<String, SObjectField> fields = objDef.fields.getMap();

Set<String> fieldSet = fields.keySet();
for(String s:fieldSet)
{
    SObjectField fieldToken = fields.get(s);
    DescribeFieldResult selectedField = fieldToken.getDescribe();
    System.debug(selectedField.getName());
}

When I try to run this through apex, I get an exception

System.NullPointerException: Attempt to de-reference a null object.

I am able to run this SOQL Query using same object,

SELECT Id, Title FROM KnowledgeArticleVersion WHERE
PublishStatus='Online' AND language ='en_US'

The framework that we are using does not allow this SOQL Query to be used and does a describe and fetches fields dynamically.

Can someone please provide a help or pointer on this ?

6
  • 1
    Which line are you getting the exception on? Commented Jul 14, 2015 at 19:46
  • On this line DescribeSObjectResult objDef = objToken.getDescribe();
    – Dave
    Commented Jul 14, 2015 at 20:14
  • Why is KnowledgeArticleVersion not in Schema.getGlobalDescribe()? appears to have a work-around.
    – Keith C
    Commented Jul 14, 2015 at 20:22
  • Keith, that link does not have any workaround. There is no license issue which is mentioned in other link. In fact, I also posted my comment to inquire if there was any solution.
    – Dave
    Commented Jul 14, 2015 at 20:40
  • The workaround is using KnowledgeArticleVersion.getSObjectType() instead of Schema.getGlobalDescribe().get('KnowledgeArticleVersion'). Commented Jul 14, 2015 at 20:41

1 Answer 1

0

I have to use the workaround as mentioned in the above comments by fellow members. KnowledgeArticleVersion.getSObjectType().getDescribe() instead of Schema.getGlobalDescribe().get('KnowledgeArticleVersion').

This is not truly dynamic in nature since I had to check in the code for name of Object and make a database call accordingly.

1
  • Marking this as answer since there was no other way found to get Knowledge Articles
    – Dave
    Commented Jul 16, 2015 at 20:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .