function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
S91084S91084 

Help on Filtering Knowledge Articles based on the custom multi-select picklist values

Hi,

 

I am trying to display the articles based on the product selected by the user that matches the software on the article.

Below is my code. I have articles that match the below criteria but not able to get the results. It is returning 0 rows.

 

public List<KnowledgeArticleVersion> getArticles(){
User u = [Select Id, Product__c, Industry__c from User where Id=:userinfo.getUserId()];
String[] Product = u.Product__c.split(';');
List<Problem__Kav> problems = [Select Id,KnowledgeArticleId,Software__c from Problem__Kav where Software__C IN :Product and PublishStatus='Online' and Language='en_US'];
if(!problems.isEmpty()){
    for(Problem__Kav p : problems)
       articleIds.add(p.KnowledgeArticleId);
}
List<KnowledgeArticleVersion> technicalarticles=[Select ArticleNumber, UrlName, Title,KnowledgeArticleId, CreatedDate, CreatedById From KnowledgeArticleVersion where PublishStatus='Online' and Language='en_US'and KnowledgeArticleId IN :articleIds order by LastPublishedDate desc];
return technicalarticles;
}

 Can anyone please help me on this.

 

If i am removing the filter Software__c IN :Product, I am getting the results.

 

Best Answer chosen by Admin (Salesforce Developers) 
S91084S91084

I figured it out. Below is the updated code.

 

public Set<String> temp = new Set<String>();
public List<String> pList = new List<String>();
public List<KnowledgeArticleVersion> getArticles(){
    Integer ii;
    List<Id> articleIds = new List<Id>();
    User u = [Select Id, Product__c, Industry__c from User where Id=:userinfo.getUserId()];
        pList = u.Product__c.Split(';');
        Integer size = pList.size();
        for(ii=0;ii<size;ii++){
            temp.add(''+pList[ii]+'');
        }
        System.debug('********TEMP LIST********'+pList);
        List<Problem__Kav> problems = [Select Id,KnowledgeArticleId,Software__c from Problem__Kav where  PublishStatus='Online' and Language='en_US' and software__c IN :temp];
        System.debug('*************LIST**************'+problems);
        if(!problems.isEmpty()){
            for(Problem__Kav p : problems)
                articleIds.add(p.KnowledgeArticleId);
        }

        List<KnowledgeArticleVersion> technicalarticles=[Select ArticleNumber, UrlName, Title, SystemModstamp, Summary, SourceId, PublishStatus, OwnerId, LastPublishedDate, LastModifiedDate, LastModifiedById, KnowledgeArticleId, IsVisibleInPrm, IsVisibleInPkb, IsVisibleInCsp, IsVisibleInApp, IsDeleted, Id, FirstPublishedDate, CreatedDate, CreatedById, ArchivedDate, ArchivedById From KnowledgeArticleVersion where PublishStatus='Online' and Language='en_US'and KnowledgeArticleId IN :articleIds order by LastPublishedDate desc];
        System.debug('***********ARTICLES**********'+technicalarticles);
        return technicalarticles;
    }

 

All Answers

sfcksfck

Have you tried this? The system.debug lines should help you see whether Product contains what you expect.

 

public List<KnowledgeArticleVersion> getArticles(){
User u = [Select Id, Product__c, Industry__c from User where Id=:userinfo.getUserId()];
String[] Product = u.Product__c.split(';');
system.debug(u.Product__C);
system.debug(Product);
... etc ...
S91084S91084
I did and have the product in the software field.
S91084S91084

I figured it out. Below is the updated code.

 

public Set<String> temp = new Set<String>();
public List<String> pList = new List<String>();
public List<KnowledgeArticleVersion> getArticles(){
    Integer ii;
    List<Id> articleIds = new List<Id>();
    User u = [Select Id, Product__c, Industry__c from User where Id=:userinfo.getUserId()];
        pList = u.Product__c.Split(';');
        Integer size = pList.size();
        for(ii=0;ii<size;ii++){
            temp.add(''+pList[ii]+'');
        }
        System.debug('********TEMP LIST********'+pList);
        List<Problem__Kav> problems = [Select Id,KnowledgeArticleId,Software__c from Problem__Kav where  PublishStatus='Online' and Language='en_US' and software__c IN :temp];
        System.debug('*************LIST**************'+problems);
        if(!problems.isEmpty()){
            for(Problem__Kav p : problems)
                articleIds.add(p.KnowledgeArticleId);
        }

        List<KnowledgeArticleVersion> technicalarticles=[Select ArticleNumber, UrlName, Title, SystemModstamp, Summary, SourceId, PublishStatus, OwnerId, LastPublishedDate, LastModifiedDate, LastModifiedById, KnowledgeArticleId, IsVisibleInPrm, IsVisibleInPkb, IsVisibleInCsp, IsVisibleInApp, IsDeleted, Id, FirstPublishedDate, CreatedDate, CreatedById, ArchivedDate, ArchivedById From KnowledgeArticleVersion where PublishStatus='Online' and Language='en_US'and KnowledgeArticleId IN :articleIds order by LastPublishedDate desc];
        System.debug('***********ARTICLES**********'+technicalarticles);
        return technicalarticles;
    }

 

This was selected as the best answer