1

I wanted to export the list of articles and related data category in excel format, I have tried to export through knowledgeArticleVersion but unable to add data category column in the list. Could please help?

Here is my code of what I tried.

controller class:
public class contactquery{

    public PageReference Export() {
        return page.testExportexcel;
    }
    Public string Artdata;
    public List<KnowledgeArticleVersion> cs{get; set;}
    public contactquery()
    {
           List<KnowledgeArticleVersion> cs1 = new list<KnowledgeArticleVersion>();
           cs = (KnowledgeArticleVersion [])database.query('Select id,ArticleNumber,ArticleType,FirstPublishedDate,Language,LastModifiedDate,LastPublishedDate,Title,urlname from KnowledgeArticleVersion where PublishStatus = \'Online\' and language = \'en_US\'');

         for (KnowledgeArticleVersion c : cs)
         {   
              System.debug(Artdata);   
               cs1.add(c);
          }
      }
 }

VF page to display list of article:

<apex:page controller="contactquery" >
 <apex:form >
 <apex:pageBlock title="List of Published Articles" >
  <div align="center"> 
        <apex:commandButton action="{!Export}" value="Export"/>
  </div>
    <apex:pageBlockTable value="{!cs}" var="arti">
        <apex:column value="{!arti.title}"/>
        <apex:column value="{!arti.Urlname}"/>
        <apex:column value="{!arti.ArticleNumber}"/>
        <apex:column value="{!arti.ArticleType}"/>
        <apex:column value="{!arti.FirstPublishedDate}"/>
        <apex:column value="{!arti.Language}"/>
        <apex:column value="{!arti.LastModifiedDate}"/>
        <apex:column value="{!arti.LastPublishedDate}"/>
    </apex:pageBlockTable>
   </apex:pageBlock>
   </apex:form>
 </apex:page>

Vf page for export fuctionality:

 <apex:page controller="contactquery" contentType="application/vnd.ms-excel#SalesForceExport.xls" cache="true">
  <apex:pageBlock title="Export Results" >
    <apex:pageBlockTable value="{!cs}" var="arti">
        apex:column value="{!arti.title}"/>
        <apex:column value="{!arti.Urlname}"/>
        <apex:column value="{!arti.ArticleNumber}"/>
        <apex:column value="{!arti.ArticleType}"/>
        <apex:column value="{!arti.FirstPublishedDate}"/>
        <apex:column value="{!arti.Language}"/>
        <apex:column value="{!arti.LastModifiedDate}"/>
        <apex:column value="{!arti.LastPublishedDate}"/>
    </apex:pageBlockTable>
   </apex:pageBlock>  
</apex:page>
Konrad Krakowiak
  • 12,285
  • 11
  • 58
  • 45
Sara
  • 11
  • 3
  • "*unable to add data category column in the list*" — what *does* happen? Do you get a build error? Does it throw an exception? Does it silently do nothing? Please edit your question to include some more information because it's hard to help you as your question stands. Thank you. – Wai Ha Lee May 02 '15 at 17:51
  • hey,since knowledgeArticleVersion object dont have datacategory name field to fetch in the list so here im facing the problem. please suggest me the object where i get all publised articles, and fetch it in the tabular format and it should have related data category name and data category group name of the article should add in the table column. – Sara May 03 '15 at 04:29

0 Answers0