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.
The following are methods for QuickActionDefaultsHandler.
public void onInitDefaults(QuickAction.QuickActionDefaults[] actionDefaults)
Type: void
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.
global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler { // Empty constructor global EmailPublisherLoader() { } // The main interface method global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) { QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null; // Check if the quick action is the standard Case Feed send email action for (Integer j = 0; j < defaults.size(); j++) { if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults && defaults.get(j).getTargetSObject().getSObjectType() == EmailMessage.sObjectType && defaults.get(j).getActionName().equals('Case.Email') && defaults.get(j).getActionType().equals('Email')) { sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(j); break; } } if (sendEmailDefaults != null) { Case c = [SELECT Status, Reason FROM Case WHERE Id=:sendEmailDefaults.getContextId()]; EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject(); // Set bcc address to make sure each email goes for audit emailMessage.BccAddress = getBccAddress(c.Reason); /* Set Template related fields When the In Reply To Id field is null we know the interface is called on page load. Here we check if there are any previous emails attached to the case and load the 'New_Case_Created' or 'Automatic_Response' template. When the In Reply To Id field is not null we know that the interface is called on click of reply/reply all of an email and we load the 'Default_reply_template' template */ if (sendEmailDefaults.getInReplyToId() == null) { Integer emailCount = [SELECT count() FROM EmailMessage WHERE ParentId=:sendEmailDefaults.getContextId()]; if (emailCount!= null && emailCount > 0) { sendEmailDefaults.setTemplateId( getTemplateIdHelper('Automatic_Response')); } else { sendEmailDefaults.setTemplateId( getTemplateIdHelper('New_Case_Created')); } sendEmailDefaults.setInsertTemplateBody(false); sendEmailDefaults.setIgnoreTemplateSubject(false); } else { sendEmailDefaults.setTemplateId( getTemplateIdHelper('Default_reply_template')); sendEmailDefaults.setInsertTemplateBody(false); sendEmailDefaults.setIgnoreTemplateSubject(true); } } } private Id getTemplateIdHelper(String templateApiName) { Id templateId = null; try { templateId = [select id, name from EmailTemplate where developername = : templateApiName].id; } catch (Exception e) { system.debug('Unble to locate EmailTemplate using name: ' + templateApiName + ' refer to Setup | Communications Templates ' + templateApiName); } return templateId; } private String getBccAddress(String reason) { if (reason != null && reason.equals('Technical')) { return 'support_technical@mycompany.com'; } else if (reason != null && reason.equals('Billing')) { return 'support_billing@mycompany.com'; } else { return 'support@mycompany.com'; } } }