1. Introduction
2. Create Flow
3. Create Apex Class
4. Test the Flow
In the dynamic landscape of business, effective communication is the cornerstone of success. For Salesforce users, maintaining seamless interaction with all team members is paramount. Whether it's announcing important updates, sharing critical information, or fostering a sense of unity, the ability to reach every user efficiently can significantly impact organizational productivity and cohesion.
In this guide, we delve into the power ofa Salesforce Flow, a robust tool that empowers users to automate processes and streamline workflows within the Salesforce ecosystem. Specifically, we'll explore how to leverage Flow to send mass emails to all users effortlessly, eliminating the need for manual intervention and ensuring that important messages reach every individual in your Salesforce organization.
By mastering this technique, you'll not only save valuable time and resources but also enhance collaboration, engagement, and ultimately, the overall effectiveness of your Salesforce implementation. So let's embark on this journey together and unlock the full potential of Salesforce Flow for seamless communication across your organization.
In today's fast-paced business environment, staying connected with every member of your Salesforce organization is essential for fostering collaboration and driving success. With Salesforce Flow, you can streamline communication processes and ensure that important messages reach every user with ease. Creating a flow to send emails to all users allows you to automate this critical aspect of communication, saving valuable time and resources while maximizing reach and engagement. In this article, we'll walk you through the step-by-step process of creating a flow within Salesforce to efficiently broadcast emails to all users, empowering you to enhance collaboration, keep everyone informed, and drive productivity across your organization.
Let's understand our scenario: We create a salesforce flow which sends email to all our users. So we need to create an apex class which invokes our salesforce flow to send the email to all users. In this class we get all the contacts and add all contact's email in the list and then send this email list to the flow. Flow will accept this email list and then find the users with those emails and then send email to all users which is found.
This is the structure of the flow:
Let's consider the step-by-step guide to create this flow:
a. Get Users:
1. First we need to create a new variable which stores the contact emails sent from apex class.
2. Now drag and drop the Get Record element from the Elements tab onto the screen and name it as Get Users.
3. Select the User as the Object.
4. Select the All Conditions Are Met (AND) from the Filter User Records.
5. Select All Records from How Many Records to Store and Automatically store all fields from How to Store Record Data.
6. Now click on Done button and connect the Start Element to this element.
b. Loop on Users:
1. Now drag and drop the Loop element from the Elements tab onto the screen and name it as Loop on Users.
2. Select the Get Users in the Collection Variable field.
3. Choose the First item to last item from the Specify Direction for Iterating Over Collection.
4. Now click on Done button and connect Get Users element to this element.
Now we need to create a new variable which is store user's email like the below figure:
c. Assign Users Email to List:
1. Drag the Assignment element onto the screen.
2. Give the
label Assign Users Email to List and the API name should
be automatically populated.
3. In variable field, select userEmails
and in operator field, select Add, and in value select
Current Item from Loop Loop_on_Users.Email
4. Then click Done
button.
We need to create a new variable which stores the contact list view link like the below figure: (To store the link in this variable, please copy and paste the contacts list view link from your salesforce org.)
d. Send Emails:
1. Drag the Action element onto the screen.
2. Write send then
select Send Email.
3. Give the label as Send Emails and the
API name should be automatically populated.
4. Enable the body
toggler and select emailBody.
5. Enable the Recipient Address
Collection toggler and select userEmails.
6. Enable the
Rich Text-Formatted Body toggler and select
$GlobalConstant.True.
7. Enable the Subject toggler and write
Test to send email.
8. Then click Done button.
Let's create an apex class which invokes our salesforce flow to send the email to all users.
public class FlowController {
public static void callFlow() {
List<String> emails = new List<String>();
List<Contact> contacts = [SELECT Id, Name, Email FROM
Contact];
for(Contact con: contacts) {
emails.add(con.Email);
}
Map<String, Object> params = new Map<String, Object>();
params.put('contactEmails', emails);
Flow.Interview.Send_Emails_To_All_Users flowInstance = new
Flow.Interview.Send_Emails_To_All_Users(Params);
flowInstance.start();
}
}
Testing the functionality of your flow is a crucial step to ensure its effectiveness and reliability before deploying it in a production environment. Here is how you test the flow to send the email.
1. Invoke the apex class like below code:
FlowController.callFlow();
This will send all the contacts' email to the flow and flow finds the users with that email. If the user exists with that email the flow will send the email to all those users.
You will get the email like the below image: