1

We are using SalesForce Service Cloud Console, and recently switched to the Case Feed layout. In order to meet our use case, in which different Email Templates and Email Recipients are required, depending the Case Type, we implemented the QuickAction.QuickActionDefaultsHandler.

This was working perfectly fine, until the new Summer 16' release. It seems that when using 'Reply' or 'ReplyAll' in the case feed, the functionality is broken - the Email Editor doesn't post the Email Thread to which we wish to 'reply' to.

Further testing in our SandBox, using the original example provided in the [QuickActionDefaultsHandler][1] reference, leads to understand something is broken. Below is the original code provided in the example:

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';
        }
    }
}

Inspecting the code with the Developer Console leads to understand that the 'getInReplyToId' paramter is not populating (equals Null), despite the 'Reply' or 'ReplyAll' button is clicked.

Any assistance would be much appreciated. Thank you.

**

  • Update

** - I was able to get the 'Reply' and 'ReplyAll' to function. I am now missing the last bit, which is to get the Template applied for the 'Reply' and 'ReplyAll'. I added: sendEmailDefaults.setInsertTemplateBody(), but that applies the Template with the latest correspondence, and not to the point on which we 'Reply'.

Below is my latest version of the Apex Class:

    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, contact.Email, Additional_To__c, Additional_CC__c, Additional_BCC__c, RecordType.name FROM Case WHERE Id=:sendEmailDefaults.getContextId()];
            EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();  
    //set TO address
         if (c.contact.Email == c.Additional_To__c){
            emailMessage.toAddress = (c.contact.Email);
            }
            else{
            if (c.Additional_To__c != null){
            emailMessage.toAddress = (c.contact.Email+' '+c.Additional_To__c);
            }
            }
    //set CC address
            emailMessage.ccAddress = (c.Additional_CC__c);
    //set BCC address        
            emailMessage.bccAddress = (c.Additional_BCC__c);

    //if In Reply To Id field is null we know the interface is called on page load
        if (sendEmailDefaults.getInReplyToId() == null) {
                Integer emailCount = [SELECT count() FROM EmailMessage WHERE ParentId=:sendEmailDefaults.getContextId()];
                if (emailCount!= null && emailCount > 0) {
                    if (c.recordtype.name  == 'Consumer'){
                        sendEmailDefaults.setTemplateId(getTemplateIdHelper('Default_Consumer_Email'));                       
                        }
                        else {
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Default_Enterprise_Email'));
                            }                
                } 
                if (c.recordtype.name  == 'Consumer'){
                        sendEmailDefaults.setTemplateId(getTemplateIdHelper('Default_Consumer_Email'));
                        }
                        else {
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Default_Enterprise_Email'));
                        }                                
           }
          //handle 'Reply' and 'ReplyAll'
           if (c.recordtype.name  == 'Consumer'){
                        sendEmailDefaults.setTemplateId(getTemplateIdHelper('Default_Consumer_Email'));  
                        sendEmailDefaults.setInsertTemplateBody(false);
                        }  
                        else{                      
                            sendEmailDefaults.setTemplateId(getTemplateIdHelper('Default_Enterprise_Email'));   
                            sendEmailDefaults.setInsertTemplateBody(false);
                            }

         }
       }

    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;
    }
}

1 Answer 1

1

Was able to sort this out, had a bug in the Apex implementation.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.