2

I am developing a test Class for a Controller .To have a sufficient test coverage I want to create ArticleTypes (_KAV) via Apex.

Is this possible ,if so then how to accomplish this?

3

My understanding is that a dedicated sObject will be available for each Article Type. It will follow the format <ArticleType>__kav for the KnowledgeArticleVersion. If your article type was FAQ then you could create a an instance as follows:

FAQ__kav testFaq = new FAQ__kav();
testFaq.Title = 'Test FAQ';
testFaq.Summary = 'KB Summary';
testFaq.URLName = 'test';
insert testFaq;

// Get the KnowledgeArticleId
FAQ__kav insertedTestFaq = [Select KnowledgeArticleId from FAQ__kav where ID = :testFaq.Id];

// Publish
KbManagement.PublishingService.publishArticle(insertedTestFaq.KnowledgeArticleId, true);   

See also:

2
  • 1
    I wonder if you will need to run it as a user who has knowledge licenses. Jun 26 '14 at 22:03
  • @DanielHoechst Maybe, I don't know. A System.runAs(user) may be required. The PublishStatus may need to be kept as 'Draft' rather than 'Online'. There aren't many examples of testing article types online that I can find. Jun 26 '14 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.