//Purpose: Set default from Address on Cases

    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 enter image description here

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!

1 Answer 1


So the EmailServicesAddress references the forwarding email address that is used by your email system to route emails. So I'm unclear about why you want to use that address as the sender address in your quick action.

However, the EmailMessage object may be of better use. On the EmailMessage object are two fields:

ParentId - which references the ID of the case that’s associated with the email

FromAddress - which references the address that originated the email.

Rather than querying for EmailServicesAddress, instead query the EmailMessage records and specify the caseId in the where clause.

SELECT Id, FromAddress, ParentId from EmailMessage where ParentId =: c.Id]

  • yeah so I want to to query for the EmailServiceAddress used to create the case right now I'm getting an out of bound error because it's querying for every single email Commented Dec 7, 2021 at 18:21
  • Ah I see, updated my answer. Commented Dec 7, 2021 at 22:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .