Avoid deliverability errors in Salesforce Flow send email action
There are two ways to send emails from a flow in Salesforce: email alerts and send email actions. I’ve used email alerts a bunch without issue, but recently shifted to the send email action. Features like more customization and the ability to log those emails in the object activity feed make it pretty attractive.
However, I ran into an issue where the send email action in Salesforce Flow (emailSimple) will fail if email deliverability is not enabled for the organization:
Single Email is not enabled for your organization or profile
This is of course expected and mainly relevant for developing and testing in sandbox. Especially in full sandboxes, you may need to keep email deliverability off in certain scenarios. The problematic part is that this error causes the entire flow to fail. Email alerts, on the other hand, fail silently when deliverability is off and don’t cause the entire flow to fail:
There are a couple of ways to handle the error without making the entire flow fail.
Add a Fault Path to send email
You can add a fault path to the emailSimple action, perform any actions you may want, then connect the fault path to the rest of the flow.
Check Email Deliverability Status before
Alternatively, you can check the email deliverability status of your org before attempting to send an email with emailSimple. To do this, you’ll need to create an invocable apex action like below.
The method tries to engage with the Messaging service – if it catches an access exception, email deliverability is off. The method returns a Boolean: true
if Email Deliverability is ON and false
if it is OFF.
public class FlowEmailUtility { @InvocableMethod(label='Get Email Deliverability Status' description='Returns true if email deliverability is enabled for the org') public static List<Boolean> emailDeliverabilityEnabled(){ List<Boolean> deliverabilityStatusList = new List<Boolean>(); Boolean EmailDeliverabilityEnabled = true; try { Messaging.reserveSingleEmailCapacity(1); Messaging.reserveMassEmailCapacity(1); } catch (System.NoAccessException e) { EmailDeliverabilityEnabled = false; } deliverabilityStatusList.add(EmailDeliverabilityEnabled); return deliverabilityStatusList; } }
Call this method in the flow and reference the output in a decision.