Newer Version Available

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

QuickActionDefaultsHandler Interface

The QuickAction.QuickActionDefaultsHandler interface lets you specify the default values for the standard Email Action on Case Feed. You can use this interface to specify the From address, CC address, BCC address, subject, and email body for the Email Action in Case Feed. You can use the interface to pre-populate these fields based on the context where the action is displayed, such as the case origin (for example, country) and subject.

Namespace

QuickAction

Usage

To specify default values for the standard Email Action on Case Feed, create a class that implements QuickAction.QuickActionDefaultsHandler.

When you implement this interface, provide an empty parameterless constructor.

QuickActionDefaultsHandler Methods

The following are methods for QuickActionDefaultsHandler.

onInitDefaults(actionDefaults)

Implement this method to provide default values for the standard Email Action in Case Feed.

Signature

public void onInitDefaults(QuickAction.QuickActionDefaults[] actionDefaults)

Parameters

actionDefaults
Type: QuickAction.QuickActionDefaults[]
This array contains only one item of type QuickAction.SendEmailQuickActionDefaults.

Return Value

Type: void

QuickActionDefaultsHandler Example Implementation

This is an example implementation of the QuickAction.QuickActionDefaultsHandler interface.

In this example, the onInitDefaults method checks whether the element passed in the array is for the standard Email Action on Case Feed. Then, it performs a query to retrieve the case that corresponds to the context ID. Next, it sets the value of the BCC address of the corresponding email message to a default value. The default value is based on the case reason. Finally, it sets the default values of the email template properties. The onInitDefaults method determines the default values based on two criteria: first, whether a reply action on an email message initiated the call to the method, and second, whether any previous emails attached to the case are associated with the call.

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}