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