You need to sign in to do that
Don't have an account?
Kumar G
KnowledgeArticleVersionStandardController is not covering in test class
Please find my test class code in code sample and suggest me how to increase code coversge.
class : public class NG_AgentContributionArticleController { // The constructor must take a ApexPages.KnowledgeArticleVersionStandardController as an argument public NG_AgentContributionArticleController(ApexPages.KnowledgeArticleVersionStandardController ctl) { SObject article = ctl.getRecord(); //this is the SObject for the new article. //It can optionally be cast to the proper article type, e.g. FAQ__kav article = (FAQ__kav) ctl.getRecord(); String sourceId = ctl.getSourceId(); //this returns the id of the case that was closed. Case c = [select subject, description, origin,Internal_only__c, Article_Requestor__c, Internal_Live_Agent_Notes__c,Article_Classification__c, Article_Sub_Classification__c from Case where id=:sourceId]; article.put('title', c.subject); //this overrides the default behavior of pre-filling the title of the article with the subject of the closed case. article.put('Solution_Section_1__c',c.description); //article.put('Solution_Section_2__c',c.Comments); article.put('Solution_Section_2__c',c.Internal_Live_Agent_Notes__c); article.put('Internal_only__c',c.Internal_Only__c); article.put('Source__c',c.origin); article.put('Article_Classification__c',c.Article_Classification__c); article.put('Article_Sub_Classification__c',c.Article_Sub_Classification__c); article.put('Case_Requestor__c',c.Article_Requestor__c); article.put('Language','en_US'); } } Test class : @isTest private class Test_NG_AgentContributionArticlecntlr { static testMethod void Test_NG_AgentContributionArticlecntlr() { String caseSubject = 'title'; String caseDesc = 'Solution_Section_1__c'; String intlvagt = 'Solution_Section_2__c'; string intrnl = 'Internal_Only__c'; String orgn = 'Source__c'; String atclcls = 'Article_Classification__c'; String atsbcls = 'Article_Sub_Classification__c'; String atreq = 'Case_Requestor__c'; String lang = 'Language'; Case c = new Case(); c.subject= caseSubject; c.description = caseDesc; c.Internal_Live_Agent_Notes__c = intlvagt; c.Internal_Only__c = False; c.Origin = orgn; c.Article_Classification__c = atclcls ; c.Article_Sub_Classification__c = atsbcls ; c.Article_Requestor__c = atreq ; //c.en_US = 'lang' ; insert c; String caseId = c.id; System.debug('Created Case: ' + caseId); ApexPages.currentPage().getParameters().put('sourceId', caseId); ApexPages.currentPage().getParameters().put('sfdc.override', '1'); ApexPages.KnowledgeArticleVersionStandardController ctl = new ApexPages.KnowledgeArticleVersionStandardController(c); try { new NG_AgentContributionArticleController (ctl); } catch(System.SObjectException e) { system.assertEquals(e.getMessage(), e.getMessage()); } System.assertEquals(caseId, ctl.getSourceId()); //System.assertEquals('From Case: '+caseSubject, ctl.getRecord().get('title')); //System.assertEquals(caseDesc, ctl.getRecord().get('details__c')); } }
After Case insertion Create knowledge article version code like below :
Add above code after case insertion and check once.
I hope it helps you.
Please let me know in case of any other assistance.
Thanks
Varaprasad
I have added above code after case insertion , i am getting the error like : Error: Compile Error: Invalid type: FAQ__kav
Please suggest on the same.
Thanks,
Naveen