Must-read
Customizing the Case Send Email Action with Apex and declarative options (opens in a new tab)
You will learn when Predefined Field Values and formulas are enough for the Case Send Email action, and how to use a QuickActionDefaultsHandler with Custom Metadata Types to set sender and recipients dynamically.
Why read this
You will also see the precedence and design trade-offs to weigh before writing Apex.
Declarative
- Fixed sender address
- Subject from a formula
- Recipient from Case Contact
Apex handler
- Sender chosen by region
- Dynamic CC and BCC
- Routing from related records
The article explains that Salesforce Service Cloud’s standard Send Email Quick Action in the Case Feed lets agents compose and send emails from a Case, with default values for recipients, sender and subject. It argues that many requirements, such as a fixed sender, a subject built from the Case Number or a recipient taken from the Case Contact, can be met declaratively through Predefined Field Values and formula expressions on the action’s configuration page.
Where logic becomes more complex, such as choosing a sender by Case region, adding an Account Relationship Manager to CC or a Compliance Team to BCC for certain Case types, the author proposes Apex using the QuickAction.QuickActionDefaultsHandler interface. The example stores region-to-sender mappings in a Custom Metadata Type called CaseRegionSetting__mdt, with a From Address field and records for North America, Europe, Asia Pacific and India. The handler class is then registered under Setup, Support Settings, as the Default Handler for Email Action.
The architectural section sets out when to choose each approach, and notes that the Apex handler takes precedence over predefined values, so conflicting defaults should be avoided. It recommends keeping addresses and routing rules in Custom Metadata rather than hardcoding them, checking that the From Address is an eligible sender identity such as a verified Org-Wide Email Address, and avoiding SOQL inside loops because the handler runs when the composer initializes.
Read the original at SalesforceCodex (opens in a new tab)