loader
Managing Salesforce Email QuickAction on Case Feed with Apex-tenetizer

In Salesforce, QuickActions allows users to perform specific actions efficiently, directly from the feed or record pages. One powerful use case is customizing the Email QuickAction on a Case feed. In this article, I’ll walk you through how to manage this QuickAction via an Apex class.

Step-by-Step Guide

1. Create the Apex Class

First, you need to create an Apex class that implements the QuickAction.QuickActionDefaultsHandler interface. This class will customize the default behavior of the Email QuickAction.

				
					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.SendEmail') && defaults.get(j).getActionType().equals('SendEmail')) {
                   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();    
            emailMessage.BccAddress = 'support_billing@mycompany.com';
            emailMessage.ToAddress  = 'anas.malik@example.com';
        }
    }
}

				
			

2. Update Support Settings

After creating the class, update your support settings:

1.Go to Setup.
2.Navigate to Support Settings.
3.Enable the Default Email Templates or Default Handler for Email Action checkbox.
4.Select the EmailPublisherLoader Apex class you created.

Explanation

The EmailPublisherLoader class customizes the Email QuickAction by implementing the QuickAction.QuickActionDefaultsHandler interface. The onInitDefaults method checks if the action is the standard Case Feed send email action and then sets custom default values for the email, such as BCC and To addresses.

Conclusion

By implementing the EmailPublisherLoader Apex class and configuring the necessary support settings, you can significantly enhance the efficiency and customization of email communication within Salesforce Case feeds. This approach not only streamlines processes for support teams but also ensures consistent and controlled communication, ultimately boosting productivity and user satisfaction. With these steps, you’re equipped to leverage Salesforce QuickActions effectively to meet your organization’s specific business needs. For more details on implementation do contact us through form below.