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