//Purpose: Set default from Address on Cases
//SRC:https://help.salesforce.com/s/articleView?id=release-notes.rn_cases_email_apex_default_fields.htm&type=5&release=214
global class emailQuickActionHelper implements QuickAction.QuickActionDefaultsHandler {
// Empty constructor
global emailQuickActionHelper() {
}
// The main interface method
global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(0);
EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();
Case c = [SELECT CaseNumber, Origin FROM Case WHERE Id=:sendEmailDefaults.getContextId()];
EmailServicesAddress E = [SELECT Id,AuthorizedSenders,EmailDomainName,IsActive,LocalPart
FROM EmailServicesAddress];
//emailMessage.FromName = e.FromAddress;
emailMessage.ValidatedFromAddress = e.EmailDomainName;
system.debug('Case Number' + c.CaseNumber);
system.debug('Email From Address:' + e.EmailDomainName);
}
}
When a user that would handle cases uses the email quick action
so if the case was created using Email-To-Case and the routing address is [email protected]
then I would want the drop down to default to [email protected]
I think both of my queries get the data I would need but I couldn't figure out how to get the EmailServiceAddress related to the case.
Thanks for any help!