Create Your First Flow – Mass Emailing Contacts

In my last post we covered how Flow’s work in Salesforce, and the elements that make them up. Now that we understand the capabilities and all the great features included in Flows, it is time to dive deeper and bring all these features to light. To do this we will go through the creation of one simple flow.

User Story – Sales users love to email their customers about new deals and overall to get their feedback about the products. However, sometimes they have to manually send one generic email to every single contact under the Account separately, whereas they could use some mass email right from Account.

Solution – Create a Flow that will be triggered from an Account record and will send an email to all the contacts that are under that particular Account. Users simply click the button and the Flow starts.

Creating The Flow

1. Navigate to Setup and type “Flows” into the quick search. Click on Flows and then click the “New Flow” button. Ensure you name your Flow and then click the “Save” button.

2. Next we need to define the variables within our Flow. Click on the “Resources” tab on the left and create all of the following variables…

Variable

Changeable resources that can be updated within the flow, or from outside (passing value through a URL or Visualforce page). Used for passing values throughout the flow…

Unique NameDescriptionTypeInput/OutputDefault Value
recordIdThe id of the Account that the Flow Action was run fromtextInput and Output

Collection Variable

Does the same trick as variables, except many values within the same data type can be stored in this resource…

Unique NameDescriptionTypeInput/OutputDefault Value
Col_EmailAddressesAll Email addresses of ContactsTextInput and Output

sObject Variables

Changeable resources where we can store a record of a specific object type, when stored in sObject variable, all the fields of that record can be accessed through the same variable…

Unique NameDescriptionTypeInput/OutputDefault Value
SOV_ContactsinloopsObject variable, contains a single Contact in the loopN/AInput and OutputContact

sObject Collection Variables

Stores multiple records of a specified object type, this resource can be used to Fast Delete, Fast Update, and Fast Create records…

Unique NameDescriptionTypeInput/OutputDefault Value
SOCV_ContactssObject variable, contains Account record that flow was triggered fromN/AInput and OutputContact

Formulas

Dynamically creates a value with the help of other resources in the flow…

Unique NameDescriptionTypeFormula
F_UserEmailEmail of the Current UserText{!$User.Email}

3. First, we need to get the Subject and the Body of the email from the User. Drag the Screen element from the Palette and drop it on the Canvas. (Users can interact with the Flow only through Screen element. It lets the flow to collect information from the User and pass it to other elements for processing.) Add the Textbox and Long Text Area fields to the screen and name them Subject & Description accordingly, click save.

4.It is time to look up for all the contacts with emails for the Account. Drag and Drop Fast Lookup Element onto the Canvas and fill the details as below (Lookup element is used to query the data):

5. In order to be able to mass email all the Contacts, we need to collect all the emails within a single Collection Variable. For this, first, drag and drop Loop element onto the Canvas and fill the details as below (Loop iterates through the values of a collection variable):

6. Next, we will need an assignment element, drag and drop it onto the Canvas and fill the details (Assignment element can set, change, add values of/to variables):

7. The last element of our flow will be Send Email static action. Drag and drop it onto the Canvas :

8. Now we need to connect the nodes, as well as set the starting element. Under every element click on the diamond shape and drag it to the next element. In the Loop element drag first nod to the Assignment element and next one (“end of loop” nod) to the Send Email element. Set the Start Element by clicking on the Down Arrow on right top corner of the Screen Element:

Testing the Flow

In the Account object, go to the Buttons, Links, and Actions section and click on “New Action” button. Add the Action to the Account Page Layout in the Page Layout click on “Mobile & Lightning Actions” section search for the button created and drag and drop it in the “Salesforce Mobile and Lightning Experience Actions” section the bottom:

You’re done! Ensure that the Account you are testing with has at least one contact with a valid email.

Heads up for releases

As mentioned before, Flow is a powerful tool for admin to create customized solutions to the levels we were not able to reach without code previously. Salesforce’ motto is “Click not code!” aligns with all the Awesome Admins’ needs. Therefore, they are trying to improve the functionality of flows. Recently, the term “Lightning Flow” is trending around, which basically means the power of Process builder and Flows. In every single release, we are seeing great improvements to these features. So, I would suggest to keep your heads up for changes/updates/improvements to the Flows and utilize those where possible.

My favourite recent improvements are to the bulkification of all flow interviews and partial save of processes. This saves so many of my cumbersome workarounds I created so that my Lightning Flow solutions don’t hit API limits. Now, I don’t need those anymore, thanks to the team behind such awesome updates!

Currently, these are optional “Critical Updates” but I would suggest everybody to go and activate those asap.

Summary

As you can guess, in the summary section I will once again brag about the greatness of the Flows!

The above example of a Flow is one of the simplest you can create. That one example can very easily be extended to ask a User “What types of contacts do you want this email to be sent? C-levels, Admins, Marketing roles, or contacts within IT department.” Then in the Fast Lookup element, you can filter the list based on the input from the User.

This little note, also, shows how flexible and easily customizable flows are. You can use this tool, almost, anywhere in your Salesforce org, from Sales to Service apps, from Service Console to Communities! Running in the background, facing users through Homepage, Record pages, Buttons, Actions.

Subscribe To The Monthly Newsletter

No Spam. No Rubbish. Just great content from the Salesforce Industry.

You have Successfully Subscribed!

8 thoughts on “Create Your First Flow – Mass Emailing Contacts

  1. Avatar

    Thanks Ben! I’d like to caution folks to think about allowing people to unsubscribe from emails sent out from Salesforce. Here’s my blog on how to add an unsubscribe link in native emails.

  2. Avatar

    I’m new to this and my flow doesn’t seem to work. I may be missing something in the fast lookup. You didn’t show the bottom half of that screen so I winged it. What is the Variable used, and the record’s fields to save in the variable. I won’t say what I did, I’ll just wait till I get the right answer! Thanks

  3. Avatar

    For three days I was trying to understand the FastLook up, Loop and assignment so that to result in a collection variable in order to use it for emailing. I was almost left bald…

    Thank you so much for this post. Literally with just two screens I understood how to properly utilise the various elements.

    If you ever visit Athens Greece, drinks are on me.

  4. Avatar

    Just finished designing the flow part I was missing. I run the flow without activating it and was prompted to the following Error: The “XXXTestEmail_Action” element in your flow has validation errors.

    I am working from a trailhead org as admin if this helps.

    What can this possibly be and how can I debug it since the email action even if it is connected to the fault email is not sending out anything.

    Thank you for your time.

  5. Avatar

    Ignore above emails. The solution works like a charm. The error observed on my side was due to a forgotten variable (formula) from previous attempts.
    What I learned is that all Errors (that will prohibit the flow from activating) need to be addressed prior to pressing the RUN button the flow otherwise this Error message will pop up. In my case the variable was not even utilised.

    Thank you for all the material you provide to the newcomers. SF would not be what it is if the community was not giving and helpful.

Leave a Reply