KnowledgeArticleVersionStandardController クラス
KnowledgeArticleVersionStandardController オブジェクトは、StandardController で提供される機能のほか、記事固有の機能を提供します。
名前空間
使用方法
上記のメソッドのほか、KnowledgeArticleVersionStandardController クラスは StandardController に関連付けられたすべてのメソッドを継承します。
例
次の例では、KnowledgeArticleVersionStandardController オブジェクトを使用してカスタム拡張コントローラを作成する方法を示します。この例では、カスタマーサポートエージェントが、ケースをクローズするときに作成するドラフト記事で自動入力された項目を表示できるようにする AgentContributionArticleController というクラスを作成します。
前提条件:
- 「FAQ」という記事タイプを作成します。手順は、Salesforce オンラインヘルプの「記事タイプの定義」を参照してください。
- [詳細] というテキストカスタム項目を作成します。手順は、Salesforce オンラインヘルプの「カスタム項目の記事タイプへの追加」を参照してください。
- 「場所」というカテゴリグループを作成して、「USA」というカテゴリに割り当てます。手順は、Salesforce オンラインヘルプの「カテゴリグループの作成と編集」および「カテゴリグループへのデータカテゴリの追加」を参照してください。
- 「トピック」というカテゴリグループを作成して、「メンテナンス」というカテゴリに割り当てます。
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}
45前の例で説明した目的で (ケースで登録された記事の変更) カスタム拡張コントローラを作成した場合、クラスを作成した後に次の手順を実行します。
- Salesforce 組織にログインし、[設定] で をクリックします。
- [編集] をクリックします。
- [APEX カスタマイズを使用] 項目にクラスを割り当てます。この操作により、新しいクラスに指定された記事タイプは、クローズケースに割り当てられた記事タイプに関連付けられます。
- [保存] をクリックします。
KnowledgeArticleVersionStandardController コンストラクタ
KnowledgeArticleVersionStandardController のコンストラクタは次のとおりです。