In the Case object, we have OOB Contact lookup(ContactId). In my project case is created using 3 methods, WebtoCase, EmailToCase, and PhoneToCase. Some time the person who created the case might live the company or will be shifted to another department. At the time the Contact on the Case record will be updated. When a Call Center agent wants to send an email to that contact, in ToAddress of SendEmail the current Contact of the case record is getting populated for WebToCase and PhoneToCase but for EmailToCase the person who initially created the case that person's contact is getting populated not the current case contact. I contacted SF support and they suggested me 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.
- If I update the case contact multiple times I see all old send email contact in ToAddress.
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.
ContactEmail
that is on the Case object?ContactEmail
uses theContactId
lookup, so when you change the Case Contact and save,ContactEmail
is automatically updated. I was asking whether you had tried to useContactEmail
(NOTContact.Email
<-- notice the '." dot) in your above code? Maybe including it in yourSELECT
statement and making it yourvaremailMessage.ToAddress
?