[コミュニティ管理] のインサイトへのカスタムアクションの作成
| 使用可能なエディション: Salesforce Classic |
| 使用可能なエディション: Enterprise Edition、Performance Edition、Unlimited Edition、および Developer Edition |
| 必要なユーザ権限 | |
|---|---|
| Visualforce ページを作成、編集、および設定する | 「アプリケーションのカスタマイズ」 |
| カスタム Visualforce コントローラを編集する | 「Apex 開発」 |
レポートの [インサイト] アクションをクリックすると、Visualforce ページによってバックグラウンドでアクションが実行されます。Visualforce ページは、標準コントローラや標準リストコントローラを使用して、標準オブジェクトまたはカスタムオブジェクトにリンクされます。
インサイトのカスタムアクションを作成する手順の概要は、次のとおりです。
-
Visualforce ページを作成します。
次のオプションを使用できます。
- 標準コントローラの使用
Visualforce ページを作成して、Salesforce の標準的なページで使用するものと同じ機能およびロジックを含めるには、このオプションを選択します。たとえば、標準取引先コントローラを使用する場合、Visualforce ページで [保存] ボタンをクリックすると、標準の取引先編集ページで [保存] をクリックした場合と同じ動作が行われます。
- 標準リストコントローラの使用
Visualforce ページを作成して、レコードセットを表示したり操作したりできるようにするには、このオプションを選択します。レコードセットを使用する既存の Salesforce ページの例として、リストページ、関連リスト、一括アクションページなどがあります。
- Apex を使用するコントローラ拡張の使用
新しい機能の公開、アプリケーションによるナビゲーションのカスタマイズ、コールアウトまたは Web サービスの使用を行う場合、またはページの情報にアクセスする方法についてより詳細な制御が必要な場合は、このオプションを選択します。
これらのオプションについての詳細は、『Visualforce 開発者ガイド』を参照してください。
- 標準コントローラの使用
-
カスタムアクションをインサイトレポートに追加します。
アクションは、レポートで返されたデータに基づいて表示されます。アクションに必要なデータを現在返しているレポートがあることを確認してください。
- [コミュニティ管理] で、新しいカスタムアクションを適用するインサイトレポートに移動します。
-
レポートで
をクリックし、カスタムアクションを選択リストから追加します。
- ユーザに適切な権限があり、ユーザがカスタムアクションを完了できることを確認します。
カスタムアクションの設定方法に応じて、ユーザはアクションの実行後にインサイトページに留まるか、内部組織のページにリダイレクトされます。インサイトの標準アクションとは異なり、ユーザはカスタムアクションの標準的な成功または失敗のメッセージを受け取りません。
例
次に、コミュニティメンバーからすべての活動���削除するカスタムアクションの例を示します。このカスタムアクションは、スパム攻撃後にコミュニティをクリーンアップする場合に役立ちます。
Apex クラスを使用してカスタムコントローラ拡張を作成し、Visualforce ページで使用します。次の DeleteAllActivityControllerExtension クラスは、カスタムコントローラ拡張の例です。
1public with sharing class DeleteAllActivityControllerExtension {
2
3 private List<Id> ids;
4 private String retURL;
5 private Database.DeleteResult[] deleteResult = null;
6 private Map<String, String> resultMap;
7 private String success = 'success';
8 private String failure = 'failure';
9
10 public DeleteAllActivityControllerExtension(ApexPages.StandardController controller) {
11 resultMap = new Map<String, String>();
12 /* The IDs you select on the Insights page are stored in a comma separated string of IDs.
13 This string is passed in a parameter called "idsList" */
14 String idsList = ApexPages.currentPage().getParameters().get('idsList');
15 //The return URL to the Insights page is passed in a parameter called "retURL"
16 retURL = ApexPages.currentPage().getParameters().get('retURL');
17 ids = idsList.split(',');
18 }
19
20 public PageReference deleteAllActivity() {
21 deleteFeedPosts();
22 deleteFeedComments();
23 //Include these two lines of code to be redirected to the Insights page after you click the action.
24 PageReference retPage = new PageReference(retURL);
25 retPage.setRedirect(true);
26 Integer failureCount = calculateFailureCount();
27 Integer successCount = ids.size() - failureCount;
28 retPage.getParameters().put(success, String.valueOf(successCount));
29 retPage.getParameters().put(failure, String.valueOf(failureCount));
30 return retPage;
31 }
32
33 private void deleteFeedPosts() {
34 List<FeedItem> feedItems = [Select Id, CreatedById FROM FeedItem WHERE CreatedById IN :ids];
35 deleteResult = Database.delete(feedItems, false);
36 //Update the resultMap with failures to calculate the failureCount
37 if(deleteResult != null) {
38 for(Integer i=0;i < deleteResult.size();i++) {
39 if (!deleteResult.get(i).isSuccess()) {
40 for(Database.Error error : deleteResult.get(i).getErrors()) {
41 resultMap.put(string.valueOf(feedItems.get(i).CreatedById), failure);
42 }
43 }
44 }
45 }
46 }
47
48 private void deleteFeedComments() {
49 List<FeedComment> feedComments = [Select Id, CreatedById FROM FeedComment WHERE CreatedById IN :ids];
50 deleteResult = Database.delete(feedComments, false);
51 //Update the resultMap with failures to calculate the failureCount
52 if(deleteResult != null) {
53 for(Integer i=0;i < deleteResult.size();i++) {
54 if (!deleteResult.get(i).isSuccess()) {
55 for(Database.Error error : deleteResult.get(i).getErrors()) {
56 resultMap.put(string.valueOf(feedComments.get(i).CreatedById), failure);
57 }
58 }
59 }
60 }
61 }
62
63 private Integer calculateFailureCount() {
64 Integer failureCount = 0;
65 for (String result : resultMap.values()) {
66 if (failure == result) {
67 failureCount++;
68 }
69 }
70 return failureCount;
71 }
72
73}このコードでは、[すべての活動を削除] ボタンがインサイトレポートに作成されます。このボタンにより、選択したメンバーのすべての投稿とコメントが削除されます。すべての非公開メッセージとファイルも削除する場合は、コードを拡張できます。
1<apex:page standardController="User"
2extensions="DeleteAllActivityControllerExtension" action="{!deleteAllActivity}"
3/>