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
srosnersrosner 

knowledge:articleCaseToolbar not rendering Attach to Case buttons

I am setting up custom VF templates to display our SF Knowledge articles. I have included the VF component knowledge:articleCaseToolbar and set up the parameters for caseID and articleID. The component renders correctly with the case information but the "Attach" and "Attach and Return Case" toolbar is not being rendered.

 

I am using the given template from the VF documentation and have tried a variety of IDs associated with the article:

 

<knowledge:articleCaseToolbar rendered="{!$CurrentPage.parameters.caseId != null}" caseId="{!$CurrentPage.parameters.caseId}" articleId="{!$CurrentPage.parameters.id}"/><br/>

 

Page is a standard controller for article type "Solution__kav" and I have a articleRendererToolBar on the page that renders fine with the Solution__kav.KnowledgeArticleid as the "articleID" parameter.

 

I have tried setting "articleID" to:

 

  • $CurrentPage.parameters.id
  • Solution__kav.KnowledgeArticleid
  • Solution__kav.MasterVersionID

I even tried passing in a static article ID to no avail.

 

Does anyone have any information on setting up this tag, if the Attach buttons are even standard functionality as part of this VF tag, or if I am going something wrong with my setup?


Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
francoisLfrancoisL

If you want this 2 buttons, you need to create them using Apex and showing them using VF language. 

 

I attached an example of code to do it:

 - Create an Apex class that will extend the standardController:

public with sharing class video {
    
    public string caseID{get;set;}
    public string kaID{get;set;}
    
    public video(ApexPages.standardController std)
    {
        caseID = ApexPages.currentPage().getParameters().get('caseid');
        kaID = ApexPages.currentPage().getParameters().get('id');
    }
    
    public void attachToCase(){
        CaseArticle ca = new CaseArticle();
        ca.CaseID = caseID;
        ca.KnowledgeArticleId = kaID;
        insert ca;
    }
}

 

In VF page:

 

<apex:page standardController="Video__kav" extensions="video" showHeader="false" sidebar="false">
<apex:includeScript value="/support/console/22.0/integration.js"/>
<script type="text/javascript">
function testCloseTab() {
            //First find the ID of the current tab to close it
            sforce.console.getEnclosingTabId(closeSubtab);
        }
        
        var closeSubtab = function closeSubtab(result) {
            //Now that we've got the tab ID, we can close it
            var tabId = result.id;
            sforce.console.closeTab(tabId);
        };

</script>
.....
 <apex:form >
  <div><apex:commandButton value="Attach" action="{!attachToCase}"/><apex:commandbutton value="Attach and Return to Case" action="{!attachToCase}" oncomplete="testCloseTab();"/></div>
  </apex:form>

 

 

I hope that helps.



 

All Answers

francoisLfrancoisL

Hi, 

 

The 2 button are not part of this VF component. We was not able to include them due to cross domain javascript issue. 

srosnersrosner

Thanks, Francois.

 

Is there anyway to re-create this functionality through API calls?

francoisLfrancoisL

If you want this 2 buttons, you need to create them using Apex and showing them using VF language. 

 

I attached an example of code to do it:

 - Create an Apex class that will extend the standardController:

public with sharing class video {
    
    public string caseID{get;set;}
    public string kaID{get;set;}
    
    public video(ApexPages.standardController std)
    {
        caseID = ApexPages.currentPage().getParameters().get('caseid');
        kaID = ApexPages.currentPage().getParameters().get('id');
    }
    
    public void attachToCase(){
        CaseArticle ca = new CaseArticle();
        ca.CaseID = caseID;
        ca.KnowledgeArticleId = kaID;
        insert ca;
    }
}

 

In VF page:

 

<apex:page standardController="Video__kav" extensions="video" showHeader="false" sidebar="false">
<apex:includeScript value="/support/console/22.0/integration.js"/>
<script type="text/javascript">
function testCloseTab() {
            //First find the ID of the current tab to close it
            sforce.console.getEnclosingTabId(closeSubtab);
        }
        
        var closeSubtab = function closeSubtab(result) {
            //Now that we've got the tab ID, we can close it
            var tabId = result.id;
            sforce.console.closeTab(tabId);
        };

</script>
.....
 <apex:form >
  <div><apex:commandButton value="Attach" action="{!attachToCase}"/><apex:commandbutton value="Attach and Return to Case" action="{!attachToCase}" oncomplete="testCloseTab();"/></div>
  </apex:form>

 

 

I hope that helps.



 

This was selected as the best answer
srosnersrosner

Worked like a charm. Thanks!

RitchiebRitchieb

Hi,

 

Any chance someone could post a test class for this class?

 

Cheers

srosnersrosner

The key piece in the unit tests is re-querying the KAV record prior to creating a standard controller based on it. This is because that field is set by the system when the KAV is inserted and will be NULL and cause an expcetion if not queried for.

 

Create your test Case and the rest of the code should work in conjunction with the controller Francois provided previously.

 

static testMethod void conArticles_Coverage() {  

     // Create new Case

     // Create new Article
     Solution__kav solKAV = new Solution__kav(Title='Test Article',URLName='Test-Article',PublishStatus='Online');
     insert solKAV;

     // Re-query the record to get the parent KnowledgeArticle ID for the new KAV.
     solKAV = [SELECT id, KnowledgeArticleId FROM Solution__kav WHERE id=: solKav.Id limit 1];

     // Create page reference and add our values as parameters for the controller
     // Case c was created previously
     ApexPages.StandardController sc = new ApexPages.StandardController(solKAV);    	
     PageReference pageRef = Page.showArticle_Solution;
     pageRef.getParameters().put('caseid',c.Id);
     pageRef.getParameters().put('id',solKav.KnowledgeArticleId);

     Test.setCurrentPage(pageRef);

     // Create an instance on our controller and assert that our IDs were set properly
     conArticles con = new conArticles(sc);
     system.assertEquals(con.caseId,c.Id);
     system.assertEquals(con.kaId,solKAV.KnowledgeArticleId);

     // Call the attachToCase method and assert that our Case now has a new CaseArticle
     con.attachToCase();
     system.assert([SELECT count() FROM CaseArticle WHERE CaseId =: c.Id] > 0);
}

 

RitchiebRitchieb

Great, Thanks! Will try that out today.

 

Cheers,

Ritchie