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?

1
  • Hey Andrew, did you tried dynamic SOQL ? Mar 10, 2016 at 16:31

1 Answer 1

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

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .