Newer Version Available
KnowledgeArticleVersionStandardController Class
KnowledgeArticleVersionStandardController objects offer article-specific functionality in addition to what
is provided by the StandardController.
Namespace
Usage
In addition to the method listed above,
the KnowledgeArticleVersionStandardController class inherits all the methods associated with StandardController.
Example
The following example shows how a KnowledgeArticleVersionStandardController object can be used to create a custom extension controller. In this example, you create a class named AgentContributionArticleController that allows customer-support agents to see pre-populated fields on the draft articles they create while closing cases.
Prerequisites:
- Create an article type called FAQ. For instructions, see “Defining Article Types” in the Salesforce online help.
- Create a text custom field called Details. For instructions, see “Adding Custom Fields to Article Types” in the Salesforce online help.
- Create a category group called Geography and assign it to a category called USA. For instructions, see “Creating and Modifying Category Groups” and “Adding Data Categories to Category Groups” in the Salesforce online help.
- Create a category group called Topics and assign it a category called Maintenance.
1swfobject.registerObject("clippy.article_case_apex", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17/** Custom extension controller for the simplified article edit page that
18 appears when an article is created on the close-case page.
19*/
20public class AgentContributionArticleController {
21 // The constructor must take a ApexPages.KnowledgeArticleVersionStandardController as an argument
22 public AgentContributionArticleController(
23 ApexPages.KnowledgeArticleVersionStandardController ctl) {
24 // This is the SObject for the new article.
25 //It can optionally be cast to the proper article type.
26 // For example, FAQ__kav article = (FAQ__kav) ctl.getRecord();
27 SObject article = ctl.getRecord();
28 // This returns the ID of the case that was closed.
29 String sourceId = ctl.getSourceId();
30 Case c = [SELECT Subject, Description FROM Case WHERE Id=:sourceId];
31
32 // This overrides the default behavior of pre-filling the
33 // title of the article with the subject of the closed case.
34 article.put('title', 'From Case: '+c.subject);
35 article.put('details__c',c.description);
36
37 // Only one category per category group can be specified.
38 ctl.selectDataCategory('Geography','USA');
39 ctl.selectDataCategory('Topics','Maintenance');
40 }
41}
421swfobject.registerObject("clippy.article_case_apex_test", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17/** Test class for the custom extension controller.
18*/
19@isTest
20private class AgentContributionArticleControllerTest {
21 static testMethod void testAgentContributionArticleController() {
22 String caseSubject = 'my test';
23 String caseDesc = 'my test description';
24
25 Case c = new Case();
26 c.subject= caseSubject;
27 c.description = caseDesc;
28 insert c;
29 String caseId = c.id;
30 System.debug('Created Case: ' + caseId);
31
32 ApexPages.currentPage().getParameters().put('sourceId', caseId);
33 ApexPages.currentPage().getParameters().put('sfdc.override', '1');
34
35 ApexPages.KnowledgeArticleVersionStandardController ctl =
36 new ApexPages.KnowledgeArticleVersionStandardController(new FAQ__kav());
37
38 new AgentContributionArticleController(ctl);
39
40 System.assertEquals(caseId, ctl.getSourceId());
41 System.assertEquals('From Case: '+caseSubject, ctl.getRecord().get('title'));
42 System.assertEquals(caseDesc, ctl.getRecord().get('details__c'));
43 }
44}
45If you created the custom extension controller
for the purpose described in the previous example (that is, to modify
submitted-via-case articles), complete the following steps after creating
the class:
- Log into your Salesforce organization and from Setup, click .
- Click Edit.
- Assign the class to the Use Apex customization field. This associates the article type specified in the new class with the article type assigned to closed cases.
- Click Save.
KnowledgeArticleVersionStandardController Constructors
The following are constructors for KnowledgeArticleVersionStandardController.
KnowledgeArticleVersionStandardController(article)
Creates a new instance of the ApexPages.KnowledgeArticleVersionStandardController class
using the specified knowledge article.
Signature
public KnowledgeArticleVersionStandardController(SObject article)
Parameters
- article
- Type: SObject
- The knowledge article, such as FAQ_kav.
KnowledgeArticleVersionStandardController Methods
The following are instance methods for KnowledgeArticleVersionStandardController.
getSourceId()
Returns the ID for the source object record when creating
a new article from another object.
Signature
public String getSourceId()
Return Value
Type: String