Create Record using Flow in Salesforce

In this post, we will implement the functionality to Create Record using Flow in Salesforce. We will also cover How to get the current record Id in Flow in Salesforce.

Screen Flows are used to guide users through a business process. We can take the input from users, make some decisions based on the input, and show the next essential screens to guide users through the process. Let’s get into the implementation.

Implementation

In this implementation, we will create Quick Action on Account that will trigger this Screen Flow. The Screen will allow the user to enter the Subject and Description. This Screen Flow will create a Case Record for the Current Account.

First, create a Screen Flow. Check Flow Basics: How to use Flow Builder in Salesforce? to know the basics of Flow and Flow Builder. Once the Screen Flow is created, add the Screen Element on the Canvas. Add Text and Text Area components on the Screen to get the inputs from the User. These inputs are stored in the Case_Subject and Case_Description. As this is the first Screen, uncheck the Previous button from Control Navigation.

Now, we want to create a Case record. Before that, create a Variable objCase with Data Type Record. Check Available for input and Available for output. For the Object, select Case. It should look something like below:

Note: Ignore the Object in the below snapshot, it is Case only. But the label for Case is Maintenance Request in my org.

objCase Case Variable
objCase Case Variable

Get Current Record Id in Flows

Now that we have the objCase object to store Case details, we can use the Assignment Element to assign the Case details to obJCase. But we also need the AccountId to assign to objCase.

To get the current record Id in Flows, just create a Text variable with recordId API Name. That is all. recordId will have the value of the current record Id. When this Flow is triggered from any Account details page, recordId will have the current record Id of the Account.

Add the Assignment Element and set the Variable values like below:

  • objCase > Subject Equals Case_Subject
  • objCase > Description Equals Case_Description
  • objCase > AccountId Equals recordId

It should look something like below:

Create Record using Flow: Assignment Element
Create Record using Flow: Assignment Element

To Create Records using Flow in Salesforce, add the Create Records Element on the Canvas. Select below values:

  • How Many Records to Create > One: As we are creating only one record.
  • How to Set the Record Fields > Use all values from a record: We can use the record variable objCase to create a record. Once the record is created successfully, Id will be added to the objCase record variable.

Note: If we haven’t created a Record variable like objCase, we can select Use separate resources, and literal values for the How to Set the Record Fields. Then we need to select the Object to create and then add the individual fields for that particular Object. As there is not any Record variable to store the Id of the new record once the record is created, we can manually assign the Id to the Variable.

It should look something like below:

Create Record Element

Finally, add one more Screen Element to show the success message with the Display Text component. As this will be the last Screen, it will show the Previous and Finish Button. After clicking Finish Button, the Flow will be closed. Verify all the details and click Save to Save the Flow.

Success Screen
Success Screen

This is how our final Flow looks like:

Create Record using Flow in Salesforce
Create Record using Flow in Salesforce

Call Flow from Quick Action

We have our Flow ready. We just need to call it from the Quick Aciton.

Go to Setup > Object Manager > Account > Buttons, Links, and Actions > New Action.

Select Action Type as Flow and select the Flow that we just created earlier. Provide the other required details and click Save. It should look something like below:

Quick Action using Flow
Quick Action using Flow

Final step is to add the Quick Action to Page Layout.

Click on Object Manager > Account > Page Layouts > Account Layout > Mobile and Lightning Actions.

Drag the Quick Action that we created earlier in the Salesforce Mobile and Lightning Experience Actions section. Click Save. That is all.

Create Record using Flow in Salesforce

This is how our implementation looks like:

Create Record using Flow in Salesforce
Create Record using Flow in Salesforce

In the next implementations, we will explore more about the Flows. Please Subscribe here if you don’t want to miss new implementations.

Thank You!

Leave a Reply

Your email address will not be published. Required fields are marked *