Ad Code

Send email alert from flow in salesforce lightning

Send email alert from salesforce lightning flow

An explainer on how to send email alerts from record-triggered flow in the Salesforce Lightning CRM.

Requirement: Send an email to the customer when the courier status is updated to Delivered by using the Salesforce Lightning Flow.

1. Create an Email template

Log in to Salesforce > Go to Setup from Gear icon

Search with the Email template in the Quick Find search box

Go to Classic Email Templates

Click the New Template button

Select Visualforce as a type of email template and Click Next

Fill in all the details

Create email template in salesforce

Check the Available For Use checkbox

Click Save

You can edit the template to add your content and other details by clicking on Edit Template Button

New email templare - salesforce

Template code
<messaging:emailTemplate subject="Courier Delivered" recipientType="Contact" relatedToType="Courier_Details__c">
This is your new Visualforce Email Template.

 2. Create an Email alert

Go to setup

Search with Email Alert in the Quick Find search box

Go to Email Alerts

Click the New Email Alert button

Fill in all the required fields (select the email template created in step 1 and choose any email field in your object as a Recipient.)

New email alert - salesforce setup

Click Save

3. Create a Record-Triggered flow to send an email alert

Go to setup

Search with Flows in the Quick Find search box

Click the New Flow button

Select Record-Triggered Flow and click Create

In the Configure Start screen,

Choose Object

Trigger the flow when: when a record is updated

Set entry conditions

          Condition Requirement: All conditions are met (AND)

          Add two conditions:

                     Delivery Status is changed to True

                     Delivery Status is equal to Delivered

(If multiple record types are created in your object, add record type condition)

Optimize the flow for: Actions and Related Records

Click Done

Salesforce lightning flow - entry criteria

Click + icon in the canvas to add a new element to the canvas (1) and Choose to Send Email Alert (2)

Salesforce flow - email alert setup

Enter email alert details and click Save

Click the Save button at the top right corner to save the flow.

Enter Flow label and API name, and click Save

Click Activate button.

We have completed the configuration. Time for unit testing.

Change the delivery status to Delivered for any record and notice the email received in the user inbox.

Email alert to customer mailbox - salesforce

At times, emails are not sent from the sandbox if the logged-in user's email address is not verified. Check for more details. 

From the above-mentioned steps, we learned how to send plain text emails. What if we need to include merge fields such as customer name and other details within an email body? Is it possible?

Yes. We can include all the fields from the respective record in the email subject or body.

Modify the template code as below

<messaging:emailTemplate subject="Courier Delivered - ref id #{!}" recipientType="Contact" relatedToType="Courier_Details__c">
<messaging:plainTextEmailBody >
    Hi {!relatedTo.Customer_Name__c},
    Your courier has been delivered.
    Team Codekiat

Notice the field values are reflected in the email

Email alert to customer mailbox - salesforce

Closing Comments

In addition to the email alerts, we can also build various other automations in the Lightning Flow without writing a single line of code. For any new functionality implementation, explore lightning flows before going with any other design.

You know why… Lightning Flow is the FUTURE!

Let us know about any interesting automation you designed using lightning flows in the comments section below.

Until then…


How to create a screen flow in Salesforce

How to use custom labels in the Salesforce lightning screen flow

Post a Comment