Salesforce Flow - Create multiple records from user input
Hello Trailblazers,
We all know how powerful Salesforce flows are. We can achieve many functionalities using flows without writing single line of code. Recently, I came across situation where I wanted to create multiple records of an object by taking inputs from user. And I came with solution using flows where we can ask user whether he wants add another record and allow him to create multiple records. We are going to discuss that solution in this blog.
We are going to use Assignment & Decision elements for
implementing this solution. Here we will ask user whether he wants to add
another record or not after entering details for one record. And basis on user’s
input we will make decisions.
We can use Loop element as well but in that case we should
have idea of how many records needs to be created. With solution explained
below user can create as many records.
Implementation Details :
For this demo we will create flow which will take lead first name, last name & company as input and it will create multiple lead records.
Create Flow
- Enter flows in Quick Find Box in Setup and open Flows screen.
- Click on New Flow button.
- You’ll get screen to select flow type. For this implementation we are going to select Screen flow as we will be adding it to Lightning Home page.
Select Screen Flow and click on Next.
- On next screen we get layout selection. Salesforce has released auto layout functionality for arrangement of node where Salesforce will automatically position elements of flow in less complex way. It is in Beta mode so it can happen that you won’t see this screen. You can go ahead with any of the options.
- Now you will land on Flow builder screen.
Create required Resources
- leadRecordsToInsert : This will be a collection variable to hold all Lead records that needs to be inserted. To create this resource follow below steps –
- Click on Manager tab inside Toolbox section.
- From this tab click on New Resource
- Enter below details on next screen
- Resource Type : Variable
- API Name : leadRecordsToInsert
- Data Type : Record
- Allow multiple values(Collection) : Checked
- Object : Lead
- tempLeadRecord : This will hold single Lead record before adding it to leadRecordsToInsert. Follow above steps to create this resource with below data.
- Resource Type : Variable
- API Name : tempLeadRecord
- Data Type : Record
- Allow multiple values(Collection) : Un-checked
- Object : Lead
- addAnotherRecord : This variable will hold user response on whether he wants to add another lead record or not upon entering details of one record. Create resource with below data.
- Resource Type : Variable
- API Name : addAnotherRecord
- Data Type : Boolean
- Allow multiple values(Collection) : Un-checked
- Default Value : {!$GlobalConstant.False}
Create Screen element for Data entry
- Drag screen element from Elements tab. Give label as Lead Entry or any other label you wish to give.
- Drag Text component from list on to the screen and give label as Lead First Name.
- Check Require checkbox to make this field mandatory for user input.
- Follow similar actions for creating Lead Last Name and Company input field.
- Now drag Toggle component on to the screen.Enter below details
- API Name : Add_Another_Record
- Label : Do you want to add another record ?
- Active Label : Yes
- Inactive Label : No
- Now click on Footer and uncheck Previous & Pause from Control Navigation section.
Create assignment element
- Drag assignment element on to the screen
- Give label as Hold Temporary Lead Record.
- Now we have to set variable values, for that maintain below assignments.
Variable | Operator | Value |
---|---|---|
tempLeadRecord > First Name | Equals | Lead_First_Name |
tempLeadRecord > Last Name | Equals | Lead_Last_Name |
tempLeadRecord > Company | Equals | Company |
- Drag assignment element on to the screen
- Give label as Add Temporary Lead Record to Collection.
- Now while setting variable , select leadRecordsToInsert as Variable, Add as Operator and tempLeadRecord as Value.
- Drag Decision element on to the screen.
- Give label as Whether to create another record.
- In the outcome details, enter Label as Take input for another record. In the Condition requirement select addAnotherRecord as resource – This is toggle which we have created on user input screen. Select value as True.
- Now click on + icon and add another outcome.
- In this new outcome enter Label as Proceed to records insertion. In the condition requirement select addAnotherRecord as resource and select value as False.
Add
Create Records element
- Drag Create Records element on to the screen.
- Enter label as Insert Lead Records.
- Select Multiple for How Many Records to Create.
- In Record Collection select leadRecordsToInsert.
Connect all elements
- Link start node to Screen element.
- Connect Lead Entry Screen element to Hold Temporary Lead Assignment element.
- Connect Hold Temporary Lead Assignment element to Add Temporary Lead Record to Collection and this element to Decision element.
- Now we have created two outcomes for Decision element. First connect this element to Lead Entry Screen and select Take Input for another record outcome when asked.
- Now again connect Decision element to Create Records element, now select Proceed to records creation as outcome.
Save your flow and test it
- Click Save button, give appropriate label.
- Add this flow component to any lightning page and test.
Comments
Post a Comment