How to Create Multiple Records Using Salesforce Flows

I worked in an organization that uses Salesforce CRM. Recently, we hired new employees for our team, and I was assigned the task of creating a workflow to create multiple employee account records for onboarding new candidates.

I decided to create a Screen flow. With this flow, the hiring team will be able to create employee account records without needing to navigate to the Employee_c tab and enter multiple fields.

In this Salesforce article, we will explore the various flow types available and learn how to create multiple records using Salesforce Flows.

Pre-requisite to Create Multiple Records Using Salesforce Flow

  • The Interview object is related to Employee_c by a Master-Detail relationship, where the Interview object is on the Master side, and Employee_c is on the Detail side.
  • We will create new Employee accounts using the Number of Employees Hired field from the Interview object.
  • Create a Number of Employees Hired field with the Number data type on the custom Interview object.
  • We must create a custom object named Employee with the following fields: Employee Name, Joining Date, Designation, and Salary. These fields need to store the employee details.

Create Multiple Records Using Salesforce Flows

Using the above scenario and the following steps, we can create multiple records using the screen flow in Salesforce.

  1. Log in to Salesforce Org. -> Click on the Setup. -> Home Tab. -> In Quick Find Box, Search for Flows.
    • You will see an option under Process Automation. -> Click on Flows. Click on the New Flow button to create a new flow.
Create Multiple Records Using Salesforce Flow
  1. In this scenario, we will create records using fields, so we have to create a screen flow. Here, you can see we have the Screen Flow type. Click on it, then click the Create button.
Create a Multiple Records in Salesforce Flow
  1. The Screen Component is used to collect user input for that. Click on the + icon and then select the Screen Interaction element. In this screen component, we will create the required fields in the given scenario.

I have created fields for Employee Name, Joining Date, Designation, and Salary to store the employee details.

Create a Multiple Records Using Salesforce Flow
  1. Now, we want the Number of candidates hired, which we will get from the interview_c object where we created the Number field.
    • We need to display this number on the screen component. For that, we have to create a variable to get data from the Interview_c object.

To create it, click on the Manager tab and then click on the New Resource option. Select Resource type as Variable, and enter the following details.

We want to fetch the record, so we have to select Data Type as Record and the Object Interview. Ensure the availability of the outside the flow checkbox for input to be checked.

Then click on the Done button.

How to Create a Multiple Records Using Salesforce Flow
  1. Then, as the Employee hired data type is Number in the Interview object, we have to add a number component to the Screen. For that, click on the Component Tab, search for the Number data type, and drag and drop it into the canvas.

Enter the Label for it; it will be displayed on the screen, and the API name will automatically populate. In the Default value, we need to select the Variable Resource we created in the above step.

Then click on the Done button.

How to Create Multiple Records in Salesforce Flow
  1. In the next step, we need to check and confirm if the user has entered a number greater than 0. For that, we have to add a Decision Element. Enter the following details and the condition for the Number of employees to be hired > 0.
How to Create Multiple Records Using Salesforce Flow
  1. We need to create records using the details we get from the screen component. We have elements like Create Records to do this. However, due to Salesforce’s Governor Limit, we cannot use any DML statement within the loop.
Create a Multiple Records Using Screen Flow in Salesforce
  1. When we get a record from the screen component, we can store it in a variable as a record and then add that record to the collection list.

For that, we have to create the following three variables:

To create it, click on the Manager tab and then click on the New Resource option. Select Resource type as Variable, and enter the following details.

Here, we want to store a Record in the variable, so we select the Data Type as Record and the Object is Employee_c.

  • EmpRecord: This will store one employee record.
  • EmpList: To create an EmpList, follow the same steps as to create an EmpRecord. The EmpRecord will be stored in the EmpList. When we create the EmpList variable, we need to click the Allow Multiple Value (Collection) checkbox.
  • RecordID: We will get this ID from the screen record ID.
Create Multiple Records Using Screen Flow in Salesforce
  1. Now, we need to assign the details entered by the user on the screen to the EmpRecord variable. For that, click on the + icon. Under the Logic Element, you will see the Assignment element. Click on it.

Enter the label and other details here. Then, we assigned the EmpRecord variable to the Values we got from the Screen Component.

Create a Multiple Records Using Screen Flow in Salesforce Lightning
  1. Now, we need to add these records to the EmpList variable we created in the above steps. Again, create an Assignment element to do so.
    • We have to create a Counter variable and set the default value to 1. This will ensure that we must enter at least 1 no of the employees to start the flow; otherwise, the flow will terminate.

Then, add the EmpRecord to the EmpList collection and increase the counter by +1.

Create a Multiple Records in Salesforce Lightning Flow
  1. After that, click the Save button and Debug the Flow. Before saving, it’s a good practice to use Flow.
  • Flow Label: Enter the flow label.
  • Flow API Name: It will automatically populate as we click the text box. This API name is used to refer to the Apex.
  • Description: Description is optional; we can introduce our flow shortly.

Then click on the Save button.

How to Create a Multiple Records in Salesforce Flow
  1. Now, we will examine the steps taken in the flow and its direction.
How to Create Multiple Records Using Salesforce Flows

This is how we can create multiple records in Salesforce Flow using the screen flow.

Conclusion

I hope you have an idea about creating multiple records using Salesforce Flow. In this article, we have explored the types of flows that can be used, considered some prerequisites, and discussed key factors to consider when creating multiple records.

Additionally, we have also seen how to create multiple records using Salesforce Flow with scenarios and explanations.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.