Here is my controller:
public with sharing class PKB_DataForScraping_MobileController extends PKB_ComponentControllerBase{
public Id artId {get;set
{
artId = value;
}
}
public String artTitle {get;set;}
public String artSummary {get;set;}
public FAQ__kav faqAnswer {
get {
List<FAQ__kav> faq;
try {
faq = [select Answer__c from FAQ__kav where PublishStatus = 'Online' and KnowledgeArticleId = :artId limit 1];
} catch (Exception e) {}
return faq[0];
}
}
}
Here is my test:
@isTest
public class PKB_Tests_Mobile {
public static Id faqId = 'kA0C0000000CgQtKAK';
static testMethod void retriveFaqAnswer() {
System.debug('Retriving FAQ answer: ');
PKB_DataForScraping_MobileController dsm = new PKB_DataForScraping_MobileController();
dsm.artId = faqId;
FAQ__kav faq = dsm.faqAnswer;
System.debug('answer: ' + faq.Answer__c);
}
}
The test runs successfully and produces a query result. But when I use the same controller code in Visualforce component provided below, I get an error page.
Visualforce component:
<apex:component controller="PKB_DataForScraping_MobileController">
<site:googleAnalyticsTracking />
<apex:attribute name="articleId" description="Article Id" type="Id" assignTo="{!artId}" required="true"/>
<apex:attribute name="key" type="String" assignTo="{!Key}" default="articleView" description="The key given to this component so the page can easily get access to it" />
<apex:attribute name="pageController" type="PKB_PageControllerBase" assignTo="{!pageController}" description="The controller for the page." />
{!faqAnswer.Answer__c}
</apex:component>
The component is used in a page that passes the artId. This error is killing me.. please help. Controller can be tested using a test class, but how do I test the component? I don't even know what is causing the error is the component.
Thanks.
return faq[0]
which will throw an exception, the best you can do isreturn null
. Or better still remove the try/catch.)