Loading
為服務建立 AI 解決方案
含動態內容的檔案:範例 Apex 類別

含動態內容的檔案:範例 Apex 類別

若要使用增強型機器人傳送動態檔案,請建立 Apex 類別以產生檔案並傳回 ContentVersionId 變數作為輸出。

必要版本

檢視 Einstein 機器人的支援版本
針對「傳訊」檢視支援的版本

此 Apex 類別會建立檔案、將檔案上載至「檔案」首頁,然後傳回檔案 ContentVersionId

//GeneratePdf Class

public with sharing class Bot_GeneratePdf {

    @InvocableMethod(label='GeneratePdf')
    public static List<Id> generatePdf() {
        PageReference myPdf = new PageReference('/apex/CreateOutboundAttachmentPage');
        
        myPdf.getParameters().put('id', '001OG000003070ZYAQ');
        
        ContentVersion version = new ContentVersion();
        version.Title = 'Account Information';
        version.PathOnClient = 'AccountInfo.pdf';
        version.VersionData = myPdf.getContentAsPDF();
        version.IsMajorVersion = true;
        insert version;
         
        Id contentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:version.Id].ContentDocumentId;
        
        ContentDistribution cd = new ContentDistribution();
        cd.Name = 'Account Information Document';
        cd.ContentVersionId = version.id;
        cd.PreferencesAllowViewInBrowser=true;
        cd.PreferencesLinkLatestVersion=true;
        cd.PreferencesNotifyOnVisit=false;
        cd.PreferencesPasswordRequired=false;
        cd.PreferencesAllowOriginalDownload=true;
        cd.PreferencesExpires=true;
        datetime expiryTime = datetime.now().addMinutes(5);
        cd.ExpiryDate = expiryTime;
        insert cd;
        
        List<Id> contentVersionId = new List<Id>();
        contentVersionId.add(version.Id);
        
        return contentVersionId;
    }
}

建立 Apex 類別之後,在機器人對話中新增一個會參照 Apex 類別的 Apex 動作對話步驟,然後將輸出儲存在識別碼清單機器人變數中。在相關聯的「檔案」對話步驟中,參照相同的識別碼機器人變數。

 
正在載入
Salesforce Help | Article