+ Start a Discussion

creating test KnowledgeArticle object

I need to create a KnowledgeArticle object for my test class. but there no DML operations allowed on KnowledgeArticle. 

Any idea how I could bypass this?


Thank you  



You don't create instances of KnowledgeArticle objects, rather you create an instance of your specific knowledge article type.  For example, I have a knowledge article type of 'MultiSection Article', which becomes an sobject in its own right of 'MultiSection_Article_KAV' - I can then instantiate this in my test as follows:


MultiSection_Article__kav article=new MultiSection_Article__kav(Title='Unit Test');


Amar cAmar c

Hi anybody used KnowledgeArticle atricle object in Test class. I created a code for putting article type and then fetch latest Knowledge atricle for putting id in CaseArticle, by using this


SELECT ArticleNumber,createdDate FROM KnowledgeArticle order by  createdDate desc LIMIT 1


in my Class i got right id.BY this ID i opened  atricle in edit mode.Its working fine But if i create test class for this,

above sql gives "list has no rows exception".I am sure article type is cretaing by test code but not fetch by this.

Any gues?is there any issue with Knowledge article in test class or i miss some concept in this.How to use knowledge article in test class.

did you get a solution for this. I am facing similar problem

prithvi kumarprithvi kumar
We can create article as below 

knowledge_kav article =new knowledge_kav(Title='test',articletype='xyz',summary='xyz',urlname='xyz');

where kav means knowledge article version.

create Datacategories and assign to knowledge article created above.