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:

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);

There are other question like mine, but I have tried all approach (using list, putting inside try catch).. my concern is why is this not returning any result?? When I try the SOQL in query editor, I positively get a result.. why not in APEX?? I already verified that field level security is enabled for the profile that this class is using. Please help.

  • 2
    Tests do not see data already in an org by default and usually would insert the data that they need to test. Not sure what the best pattern for __kav objects is (i.e. whether they can be inserted) but a short term fix should be to use the @IsTest(SeeAllData=true) option to see the test run all the way through and then see if you can insert the objects instead. – Keith C Dec 12 '14 at 21:37
  • Can you output the value of artId with a system.debug just before the soql query ? – Mihai Neagoe Dec 12 '14 at 21:38
  • Keith: I get no results even after using SeeAllData=true – XurajB Dec 12 '14 at 21:40
  • Mihai: Yes I get the exact value of artId like I assigned – XurajB Dec 12 '14 at 21:40
  • 1
    Mihai: Changing the API version of the test gave me a result.. now need to check with VF pages. Thanks – XurajB Dec 12 '14 at 21:55

Changing the class version as indicated here https://developer.salesforce.com/forums/ForumsMain?id=906F000000090k9IAA will solve the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.