function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TamilTamil 

Send Email Quick Action : QuickActionDefaultsHandler

In the Case object, I have Contact lookup. Until the case is not closed the contact lookup will keep changing as per business requirements. My issue is when the user tries to send an email the Sendmail Email action is not picking the current contact instead it is picking Old send email contact . I contacted SF Support and SF support suggested to use: QuickAction.QuickActionDefaultsHandler
Here is the code I am using for SendEmail quick action.
global class SendEmailQuickAction implements QuickAction.QuickActionDefaultsHandler {
    global SendEmailQuickAction() {
    }
    global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
        Id ContId;
        QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(0);
        if(sendEmailDefaults.getActionName() == 'Case.SendEmail1' && sendEmailDefaults.getActionType() == 'SendEmail')
        {
            ContId = sendEmailDefaults.getContextId();
            EmailMessage varemailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();   
            Case varCase =  [SELECT Contact.Email,Contact.Name,Contact.Id,ContactId from Case Where Id = :ContId Limit 1];
            varemailMessage.ToAddress = '';
            varemailMessage.ToAddress = varCase.ContactId;
        }        
    }
}


Now issue is
  • I am not able to populate Contact. When I use ContactID I am seeing the ID not the contact Name.
  • I am seeing all old send email contact in ToAddress when I try to send an email.
I need some help with ToAddress. Can someone help me pointing what mistake I am doing in the code. My requirement is ToAddress should have only Case Contact. This issue is happening for Email to Case. For other type of case i dont have this issue.

sample screen shot:
User-added image