0

I have a running implementation of a customized Email Publisher in the Case Feed, which implement QuickActionDefaultHandler to pre-populate Email Templates based on my Cases Record Type. Below is 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);
            }
            }

In addition, I am setting the TO address according a combination of the Case Contact and the custom field - 'Additional_To__c'. The above solution is setting the TO properly, but when the Case Contact does exist in the 'Additional_To__c' as follows:

enter image description here

The outcome is a duplicity of the Case Contact - 'test@test.com': enter image description here

0

I was able to resolve this by using 'indexOf' for String 'includes' condition as follows:

 //set TO address
     String contactEmail = c.contact.Email; 
     if (c.contact.Email == c.Additional_To__c){
        emailMessage.toAddress = (c.contact.Email);
        }
        else{
            if (c.Additional_To__c != null){
                //contactEmail is included in Additional TO
                if (c.Additional_To__c.indexOf(contactEmail) != -1){
                    emailMessage.toAddress = (c.Additional_To__c);
                    }
            else{
                emailMessage.toAddress = (c.contact.Email+' '+c.Additional_To__c);
                }
            }
        }
| improve this answer | |

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.