Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
KnowledgeArticleVersionStandardController Class
Namespace
Usage
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.
- Create an article type called FAQ. For instructions, see “Create Article Types” in the Salesforce online help.
- Create a text custom field called Details. For instructions, see “Add 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 “Create and Modify Category Groups” and “Add Data Categories to Category Groups” in the Salesforce online help.
- Create a category group called Topics and assign it a category called Maintenance.
1/** Custom extension controller for the simplified article edit page that
2 appears when an article is created on the close-case page.
3*/
4public class AgentContributionArticleController {
5 // The constructor must take a ApexPages.KnowledgeArticleVersionStandardController as an argument
6 public AgentContributionArticleController(
7 ApexPages.KnowledgeArticleVersionStandardController ctl) {
8 // This is the SObject for the new article.
9 //It can optionally be cast to the proper article type.
10 // For example, FAQ__kav article = (FAQ__kav) ctl.getRecord();
11 SObject article = ctl.getRecord();
12 // This returns the ID of the case that was closed.
13 String sourceId = ctl.getSourceId();
14 Case c = [SELECT Subject, Description FROM Case WHERE Id=:sourceId];
15
16 // This overrides the default behavior of pre-filling the
17 // title of the article with the subject of the closed case.
18 article.put('title', 'From Case: '+c.subject);
19 article.put('details__c',c.description);
20
21 // Only one category per category group can be specified.
22 ctl.selectDataCategory('Geography','USA');
23 ctl.selectDataCategory('Topics','Maintenance');
24 }
25}1/** Test class for the custom extension controller.
2*/
3@isTest
4private class AgentContributionArticleControllerTest {
5 static testMethod void testAgentContributionArticleController() {
6 String caseSubject = 'my test';
7 String caseDesc = 'my test description';
8
9 Case c = new Case();
10 c.subject= caseSubject;
11 c.description = caseDesc;
12 insert c;
13 String caseId = c.id;
14 System.debug('Created Case: ' + caseId);
15
16 ApexPages.currentPage().getParameters().put('sourceId', caseId);
17 ApexPages.currentPage().getParameters().put('sfdc.override', '1');
18
19 ApexPages.KnowledgeArticleVersionStandardController ctl =
20 new ApexPages.KnowledgeArticleVersionStandardController(new FAQ__kav());
21
22 new AgentContributionArticleController(ctl);
23
24 System.assertEquals(caseId, ctl.getSourceId());
25 System.assertEquals('From Case: '+caseSubject, ctl.getRecord().get('title'));
26 System.assertEquals(caseDesc, ctl.getRecord().get('details__c'));
27 }
28}- Log into your Salesforce organization and from Setup, enter Knowledge Settings in the Quick Find box, then select Knowledge Settings.
- 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)
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()
Signature
public String getSourceId()
Return Value
Type: String