Loading
Experience Cloud
為標記項目設定 Apex 觸發

為標記項目設定 Apex 觸發

使用觸發以建立自訂進階仲裁邏輯,其會自動標記您 Experience Cloud 網站中的項目。

必要版本

提供版本:Salesforce Classic 與 Lightning Experience
提供版本:EnterprisePerformanceUnlimitedDeveloper Edition
需要的使用者權限
若要建立觸發: 修改所有資料
小秘訣
小秘訣 您知道您可以在 UI 中執行此操作嗎?大多數網站不需要自訂仲裁觸發。您可以直接在「體驗工作區」中建立仲裁規則與條件。如需詳細資訊,請參閱建立規則以仲裁您的 Experience Cloud 網站

使用觸發來自動標記項目可讓您在背景仲裁 Experience Cloud 網站。只有版主才能看到這些標記。您可以在「體驗工作區」中檢視標記、在 API 中對其進行查詢,或使用自訂報告類型針對已標記項目、其項目標記最多的人員等建立報告。

建立觸發時請考慮下列事項:

  • 在插入對 FeedItem、FeedComment、ChatterMessage 或 ContentDocument 進行觸發之後才建立 Apex。
  • 定義在 FeedComment、FeedItem、ChatterMessage 或 ContentDocument 作為父系的情況下,若符合便會建立 NetworkModeration (標記) 記錄的條件。
範例
範例

此觸發會自動標記您網站中包含 BadWord 的貼文。

trigger autoflagBadWordOnPost on FeedItem (after insert) {

    List<NetworkModeration> flags = new List<NetworkModeration>();
    
    for (FeedItem rec : trigger.new) {
        if (!<NetworkId>.equals(rec.networkScope)){
            continue;
        }

        if (rec.body.indexOf('BadWord') >= 0) {
            NetworkModeration nm = new NetworkModeration(EntityId = rec.id, Visibility = 'ModeratorsOnly');
            flags.add(nm);
        }
    }
    
    if (!flags.isEmpty()) {
        insert(flags);
    }
}

註解上的類似觸發如下所示。

trigger autoflagBadWordOnComment on FeedComment (after insert) {
    List<NetworkModeration> flags = new List<NetworkModeration>();
    
    for (FeedComment rec : trigger.new) {
        if (!<NetworkId>.equals(rec.networkScope)) {
            continue;
        }

        if (rec.commentBody.indexOf('BadWord') >= 0) {
            NetworkModeration nm = new NetworkModeration(EntityId = rec.id, Visibility = 'ModeratorsOnly');
            flags.add(nm);
        }
    }
    
    if (!flags.isEmpty()){
        insert(flags);
    }
}
 
正在載入
Salesforce Help | Article