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
Wim Velzeboer 6Wim Velzeboer 6 

Custom knowledge:articleList not working

I want to build my own custom <knowledge:articleList> container, but I can't seem to get it working.

My Configuration:
The DataCategoryGroup is called: Knowledge_Base
The DataCategory is: testCategory
I have 10 articles in Knowledge_Base:testCategory

My VisualForce Page with the standard <knowledge:articleList> container (see below) will show the list of 10 Articles:
<apex:page>
    <apex:pageBlock title="My Searchresults">
        <knowledge:articleList articleVar="article" categories="Knowledge_Base:testCategory" hasMoreVar="false" pageSize="10">
            <apex:outputLink value="{!URLFOR($Action.KnowledgeArticle.View, article.id,['popup' = 'true'])}">{!article.title}</apex:outputLink><br/>
            <small>{!article.lastModifiedDate},{!article.Id}</small>
            <hr/>
        </knowledge:articleList>
    </apex:pageBlock>
</apex:page>

When I try to build it with a custom Apex Class and VisualForce Page (see below) it will not work.

APEX CLASS:
public class cc_debug_search {
    public List<KnowledgeArticleVersion> getSearchResults(){ 
        String qryString = 'SELECT Id, title, UrlName, LastPublishedDate,LastModifiedById, KnowledgeArticleId FROM KnowledgeArticleVersion WHERE (PublishStatus = \'online\' and Language = \'en_US\')';
        List<KnowledgeArticleVersion> articleList= Database.query(qryString);
        return articleList;
    }
}
  

VISUALFORCE PAGE:
<apex:page controller="cc_debug_search">
    <apex:pageBlock title="My Custom Searchresults">
        <apex:repeat value="{!SearchResults}" var="article">
            <apex:outputLink value="{!URLFOR($Action.KnowledgeArticle.View, article.id,['popup' = 'true'])}">{!article.title}</apex:outputLink><br/>
            <small>{!article.lastModifiedDate},{!article.Id}</small>
            <hr/>
        </apex:repeat>
    </apex:pageBlock>
    </apex:page>
  

This will return the error message:
Unable to Access Page
The value of a parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.



MY ANALYSIS:

It goos wrong on the {!URLFOR($Action.KnowledgeArticle.View, article.id,['popup' = 'true'])} part. 
It seems the returned Id is wrong. I also tried to replace it with:

 - {!URLFOR($Action.KnowledgeArticle.View, article.KnowledgeArticleId,['popup' = 'true'])}
 - {!URLFOR($Action.KnowledgeArticle.View, LEFT(article.Id,15),['popup' = 'true'])}  to get a 15 char ID
 - {!URLFOR($Action.KnowledgeArticle.View, LEFT(article.KnowledgeArticleId,15),['popup' = 'true'])}  to get a 15 char ID

All without result...

Can anyone help me with this?
Wim Velzeboer 6Wim Velzeboer 6

Addition:

I found out that if I use the article.KnowledgeArticleId (15 char version) and copy past it as String in the script below, it does work:
{!URLFOR($Action.KnowledgeArticle.View, 'kA124000000TbBo',['popup' = 'true'])}

But if I change it to this below, it doesn't work:
{!URLFOR($Action.KnowledgeArticle.View, LEFT(article.KnowledgeArticleId,15),['popup' = 'true'])} 

<p>{!LEFT(article.KnowledgeArticleId,15)}</p>  does return kA124000000TbBo
 

Francesco SciutoFrancesco Sciuto
Do you have any update on this? I am also struggling to get this work, I tried with both knowledge:ArticleList and with the apex:repeat and I got the sdame error:

<apex:repeat id="faqrepeat" var="article" value="{!articleList}">
<url>
      <loc>{!URLFOR($Action.KnowledgeArticle.View, article.id)}</loc>
</url>
</apex:repeat>

Controller:

 public List<KnowledgeArticleVersion> articleList
 {
    get
    {   
         List<KnowledgeArticleVersion> kav = [SELECT Id, KnowledgeArticleId, lastPublishedDate
                                       FROM KnowledgeArticleVersion
                                       WHERE PublishStatus = 'Online'
                                       AND Language = 'en_US'
                                       AND IsLatestVersion = true
                                       AND KnowledgeArticleId IN :kaIds LIMIT 10];    
    }
}

I hope it can give you some help :)
Francesco SciutoFrancesco Sciuto
Ps: I forgot, in the Debug logs everythign seems fine, the KnowledgeArticles are retrieved with the correct fields, I guess the issue is in the Action 
Wim Velzeboer 6Wim Velzeboer 6
Hello Francesco,
I haven't solved it, but I did manage to find a work-a-round:
<apex:outputLink value="{!IF(FIND('/apex/',$CurrentPage.URL)>0,LEFT($CurrentPage.URL, FIND('/apex/',$CurrentPage.URL)))}articles/{!SUBSTITUTE(article.ArticleType,'__kav','')}/{!article.UrlName}">
  {!article.title}
</apex:outputLink>
What I do first is the get the current URL and remove everything to the right (if you use community pages, don't forget to add those) that you end up with something like https://yourorgname.my.salesforce.com/   There you add 'articles/' and the article type name without the '__kav' and add '/' and finaly add the article UrlName. 

Then you end up with
https://yourorgname.my.salesforce.com/articles/{articleTypeName without the __kav}/{article UrlName}

Don't forget to add the ArticleType and UrlName to your Apex:
public List<KnowledgeArticleVersion> articleList
 {
    get
    {   
         List<KnowledgeArticleVersion> kav = [SELECT Id, KnowledgeArticleId, lastPublishedDate, ArticleType, UrlName 
                                       FROM KnowledgeArticleVersion
                                       WHERE PublishStatus = 'Online'
                                       AND Language = 'en_US'
                                       AND IsLatestVersion = true
                                       AND KnowledgeArticleId IN :kaIds LIMIT 10];    
    }
}
It isn't a very beautifull solution but it works... 

Good luck with it!