You need to sign in to do that
Don't have an account?
Knowledge article
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.
I dont think there is any issue .Create a knowledge artcile version record and then publish that using apex methods and then try to query with knowledge article Id in test class itself you will get .Let me know if you need more help.
I my class I am getting by query , issue is in test class. 2nd thing is that necessary to be publish, in my class code i did not publish it but i am able to get by query but when i call same mehtod from test class, query return to list has no rows exception?
my class code is something like this
product__kav article = new product__kav();
article.put('title', 'test');
String Urlname = NewString+''+System.now().getTime();
article.put('UrlName',Urlname);
..
insert article;
}
catch(Exception ex)
{
System.debug('Exception on article....'+ex.getMessage());
}
put all values for article , did not change Status to publish
and fetch again in next line for getting of knwledge article and open a edit page directly by id (using page refrence)
KnowledgeArticle knowledgeObj = [SELECT ArticleNumber,createdDate FROM KnowledgeArticle order by createdDate desc LIMIT 1];
i am getting knowledgeObj.id in my class when i run code on button click but when i call this in test class
like this calling above code
try
{
createArticle.createArticleOnCase(crCase.Id);
}
i got list has no rows to return mean while article product_kav is created i got that id on try block after insert and i did not get knowledge article id for recent article same like when i run the code ....
is any concept is missing...?
thanks mohit,
should i have to create knowledgeArticleversion first to get knowledge article ?but i am getting knowledge article without doing his in class?
Sorry for delay reply but yes create a knowledge artcile version and there is special publish method and please use that as well.Thanks