0

I have the following code

public with sharing class pkb_ArticleController {

public KnowledgeArticleVersion[] articles {get {

return [SELECT Id, Title, Summary, UrlName, ArticleType , LastModifiedDate, LastPublishedDate, FirstPublishedDate, ArticleNumber
                    FROM KnowledgeArticleVersion
                    WHERE PublishStatus = 'Online'
                    AND Language = 'nl_NL'
                    WITH DATA CATEGORY FAQ__c AT Subcategory__c
                    ORDER by LastPublishedDate DESC
                    LIMIT :maxrows];
                } set;}  

public integer maxrows {get;set;}
public string categoryname {get;set;}

public pkb_ArticleController() {

    }

    public KnowledgeArticleVersion[] getArticles() {

        return articles;
    }
}

However, I would like Subcategory__c to be dynamic

In the documentation I see that bind variable (like :maxrows) doesn't work.

Is there a workaround?

  • Hey Andrew, did you tried dynamic SOQL ? – Jitendra Zaa Mar 10 '16 at 16:31
0

It worked with public with sharing class us_pkb_ArticleController {

public KnowledgeArticleVersion[] articles {get {

String selection = 'SELECT Id, Title, Summary, UrlName, ArticleType , LastModifiedDate, LastPublishedDate, FirstPublishedDate, ArticleNumber'; selection += ' FROM KnowledgeArticleVersion'; selection += ' WHERE PublishStatus = \'Online\''; selection += ' AND Language = \'nl_NL\''; selection += ' WITH DATA CATEGORY FAQ__c AT '+ categoryname; selection += ' ORDER by LastPublishedDate DESC'; selection += ' LIMIT :maxrows'; return Database.query(selection);} set;}

public integer maxrows {get;set;} public string categoryname {get;set;}

public us_pkb_ArticleController() {

}

public KnowledgeArticleVersion[] getArticles() {

    return articles;
}

}

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.