項目にフラグを設定する Apex トリガの設定
トリガを使用して、コミュニティで項目に自動的にフラグを設定する高度なカスタムモデレーションロジックを作成します。
| 使用可能なエディション: Salesforce Classic |
| 使用可能なエディション: Enterprise Edition、Performance Edition、Unlimited Edition、および Developer Edition |
| 必要なユーザ権限 | |
|---|---|
| トリガを作成する | 「すべてのデータの編集」 |
トリガを使用して自動的に項目にフラグを設定すると、コミュニティをバックグラウンドでモデレートできます。このようなフラグは、モデレータにのみ表示されます。[コミュニティ管理] ページでの [フラグ付き投稿] フィード内のフラグの表示、API でのフラグのクエリ、カスタムレポートタイプを使用したフラグ付き項目やフラグ付き項目が最も多いユーザなどに関するレポートの作成ができます。
トリガを作成するときは、次の点に留意してください。
- Apex は、FeedItem、FeedComment、ChatterMessage、または ContentDocument にトリガを挿入した後に作成します。
- 条件は、満たされたら FeedComment、FeedItem、ChatterMessage、または ContentDocument を親として NetworkModeration (フラグ) レコードを作成するように定義します。
例
次のトリガは、コミュニティ内の BadWord を含む投稿に自動的にフラグを設定します。
1trigger autoflagBadWord on FeedItem (after insert) {
2 for (FeedItem rec : trigger.new) {
3 if (!<CommunityId>.equals(rec.networkScope))
4 continue;
5
6 if (rec.body.indexOf('BadWord') >= 0) {
7 NetworkModeration nm = new NetworkModeration(entityId=rec.id, visibility='ModeratorsOnly');
8 insert(nm);
9 }
10 }
11}コメントに対する同様のトリガは、次のようになります。
1trigger autoflagBadWord on FeedComment (after insert) {
2 for (FeedComment rec : trigger.new) {
3 if (!<CommunityId>.equals(rec.networkScope))
4 continue;
5
6 if (rec.commentBody.indexOf('BadWord') >= 0) {
7 NetworkModeration nm = new NetworkModeration(entityId=rec.id, visibility='ModeratorsOnly');
8 insert(nm);
9 }
10 }
11}