QuickActionDefaultsHandler not working in Lightning?

I can’t seem to get the QuickActionDefaultsHandler to work at all in Lightning.

Is there anybody that has got it working? Specifically, I’m using the Service Console.

Just to be clear: the “Enable Default Email Templates or the Default Handler for Email Action” is set and is pointing to the correct class.

Update from 2019: this now works in Lightning! See https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_cases_email_apex_default_fields.htm

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Indeed, this is not supported in Lightning.
In my organization, I mainly overcame this by including the desired logic in a unified Custom HTML email template, and set it as a default for the Email action. Also, I added the recipient list, email subject, FROM, to, cc and bcc fields as formulas in predefined fields on that same Email action.
If you’ll share your class here, along with the various email templates, i’ll be able to assist.

Method 2

I was facing the same issue and I confirm it it works in lightning. However, I found out following issues in my code:

Mostly people just copy and paste code from here or any article: https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_cases_email_apex_default_fields.htm

global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
        QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(0);
        EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject(); 

        Case c = [SELECT CaseNumber, Priority FROM Case WHERE Id=:sendEmailDefaults.getContextId()];

        // If case severity is “High,” append “<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3459555a555351464774555759511a575b59">[email protected]</a>” to the existing (and possibly blank) BCC field
        if (c.Priority != null && c.Priority.equals('High')) { // Priority is 'High'
            emailMessage.BccAddress = '<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="18757976797f7d6a6b58797b757d367b7775">[email protected]</a>';        
        }        
}

But necessarily “defaults.get(0)” may not be the one you are using on
layout. So you need to iterate over all quick actions and find out the
correct one as I’m doing below. My quick action developer name is
“Email_Member”.

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_Member') && defaults.get(j).getActionType().equals('SendEmail')) {
                   sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(j);
                   break;
            }
        }
        system.debug(sendEmailDefaults);

        if (sendEmailDefaults != null) {
            Case c = [SELECT CaseNumber, Contact.Email, Priority FROM Case WHERE Id=:sendEmailDefaults.getContextId()];
            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();
            emailMessage.BccAddress = null;
            emailMessage.ToAddress = null;//keep null, contact email will come by default
      }     
    }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x