You need to sign in to do that
Don't have an account?
noedskov
How to create a knowledgebase__kav with PublishStatus = Online for testing?
Hi,
I have a test method which tests a number of Knowledgebase related objects. In my Apex Class, I have the following code:
String queryvar = 'FIND \'' + '*' + searchQ + '*' + '\'' + ' IN ALL FIELDS Returning ' + 'Knowledgebase__kav(Id, Title, Summary, UrlName WHERE PublishStatus =\'Online\')'; List<List<SObject>> searchList = search.query(queryvar); Knowledgebase__kav [] documents = ((List<Knowledgebase__kav>)searchList[0]); if (!documents.isEmpty()) { for (Knowledgebase__kav c : documents) { // Do stuff... } } else { // Do different stuff... }
In my test method I then create a new Knowlegebase__kav object but when trying to set PublishStatus = 'Online', I'm told the field is not writeable. I need to mark it as 'Online' as that's what my Apex Class is looking for.
Any great ideas?
Cheers.
/Søren Nødskov Hansen
Hi,
Unfortunately, it's not possible to create Online Article with the API today.
As workaround, I think that you can update your code to take a parameter 'Draft'/'Online'. Your real code can use the default value Online and your test class can run the code using Draft mode.
All Answers
Just a quick update...
I tried, in my test method, to select a user who has the "Knowledge User" flag set to true and encapsulate the line of code where I set the PublishStatus using runAs...
Something like this:
However, this didn't do the trick either. I really hope someone out there knows how to solve this problem.
If you know (or think you know) what I'm doing wrong, please let me know. It's getting very frustrating and this is the only part preventing us from putting our code into production.
Thanks.
/Søren Nødskov Hansen
Hi,
Unfortunately, it's not possible to create Online Article with the API today.
As workaround, I think that you can update your code to take a parameter 'Draft'/'Online'. Your real code can use the default value Online and your test class can run the code using Draft mode.
Thanks for pointing out the obvious, FrancoisLptx!
Documentation
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_knowledge_kbManagement.htm