この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

Newer Version Available

This content describes an older version of this product. View Latest

QuickActionDefaultsHandler インターフェース

QuickAction.QuickActionDefaultsHandler インターフェースでは、ケースフィードの標準の [メール] アクションのデフォルト値を指定できます。このインターフェースを使用して、ケースフィードの [メール] アクションの [送信元アドレス]、[CC アドレス]、[BCC アドレス]、[件名]、および [メール内容] を指定できます。このインターフェースを使用して、ケース発生源 (国など) や件名など、アクションが表示されるコンテキストに基づいてこれらの項目を自動入力できます。

名前空間

QuickAction

使用方法

ケースフィードの標準の [メール] アクションのデフォルト値を指定するには、QuickAction.QuickActionDefaultsHandler を実装するクラスを作成します。

このインターフェースを実装する場合は、パラメータのない空のコンストラクタを用意します。

QuickActionDefaultsHandler のメソッド

QuickActionDefaultsHandler のメソッドは次のとおりです。

onInitDefaults(actionDefaults)

このメソッドを実装して、ケースフィードの標準の [メール] アクションのデフォルト値を指定します。

署名

public void onInitDefaults(QuickAction.QuickActionDefaults[] actionDefaults)

パラメータ

actionDefaults
型: QuickAction.QuickActionDefaults[]
この配列には、QuickAction.SendEmailQuickActionDefaults 型の 1 つの項目のみが含まれます。

戻り値

型: void

QuickActionDefaultsHandler の実装例

これは、QuickAction.QuickActionDefaultsHandler インターフェースの実装例です。

この例では、onInitDefaults メソッドを使用して、配列で渡された要素がケースフィードの標準の [メール] アクション用であるかどうかを確認します。次に、クエリを実行してコンテキスト ID に対応するケースを取得します。次に、対応するメールメッセージの BCC アドレスの値をデフォルト値に設定します。デフォルト値はケースの原因に基づきます。最後に、メールテンプレートのプロパティのデフォルト値を設定します。onInitDefaults メソッドは、2 つの条件に基づいてデフォルト値を決定します。1 つ目の条件は、メールメッセージの返信アクションでメソッドへのコールが開始されたかどうか、2 つ目の条件は、ケースに関連付けられた以前のメールがコールに関連付けられているかどうかです。

1global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler {
2    // Empty constructor
3    global EmailPublisherLoader() {
4    }
5    
6    // The main interface method
7    global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
8        QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null;
9    
10    
11        // Check if the quick action is the standard Case Feed send email action
12        for (Integer j = 0; j < defaults.size(); j++) {
13            if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults && 
14               defaults.get(j).getTargetSObject().getSObjectType() == 
15                   EmailMessage.sObjectType && 
16               defaults.get(j).getActionName().equals('Case.Email') && 
17               defaults.get(j).getActionType().equals('Email')) {
18                   sendEmailDefaults = 
19                       (QuickAction.SendEmailQuickActionDefaults)defaults.get(j);
20                   break;
21            }
22        }
23        
24        if (sendEmailDefaults != null) {
25            Case c = [SELECT Status, Reason FROM Case 
26                      WHERE Id=:sendEmailDefaults.getContextId()];
27        
28            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();    
29            // Set bcc address to make sure each email goes for audit
30            emailMessage.BccAddress = getBccAddress(c.Reason);
31            
32            /* 
33            Set Template related fields 
34            When the In Reply To Id field is null we know the interface 
35            is called on page load. Here we check if 
36            there are any previous emails attached to the case and load 
37            the 'New_Case_Created' or 'Automatic_Response' template.
38            When the In Reply To Id field is not null we know that 
39            the interface is called on click of reply/reply all 
40            of an email and we load the 'Default_reply_template' template
41            */
42            if (sendEmailDefaults.getInReplyToId() == null) {
43                Integer emailCount = [SELECT count() FROM EmailMessage 
44                                      WHERE ParentId=:sendEmailDefaults.getContextId()];
45                if (emailCount!= null && emailCount > 0) {
46                    sendEmailDefaults.setTemplateId(
47                        getTemplateIdHelper('Automatic_Response'));
48                } else {
49                    sendEmailDefaults.setTemplateId(
50                        getTemplateIdHelper('New_Case_Created'));
51                }
52                sendEmailDefaults.setInsertTemplateBody(false);
53                sendEmailDefaults.setIgnoreTemplateSubject(false);
54            } else {
55                sendEmailDefaults.setTemplateId(
56                    getTemplateIdHelper('Default_reply_template'));
57                sendEmailDefaults.setInsertTemplateBody(false);
58                sendEmailDefaults.setIgnoreTemplateSubject(true);
59            }
60        }
61    }
62    
63    private Id getTemplateIdHelper(String templateApiName) {
64        Id templateId = null;
65        try {
66            templateId = [select id, name from EmailTemplate 
67                          where developername = : templateApiName].id;   
68        } catch (Exception e) {
69            system.debug('Unble to locate EmailTemplate using name: ' + 
70                templateApiName + ' refer to Setup | Communications Templates ' 
71                    + templateApiName);
72        }
73        return templateId;
74    }
75private String getBccAddress(String reason) {
76        if (reason != null && reason.equals('Technical')) 
77            { return 'support_technical@mycompany.com'; } 
78        else if (reason != null && reason.equals('Billing')) 
79            { return 'support_billing@mycompany.com'; } 
80        else { return 'support@mycompany.com'; }
81    }
82
83    
84}