Screen Flows | Clone Records using Flows

In this blog I am going to demonstrate how to Clone Records with all the field values using Screen Flows and Auto-Launched Flows in Salesforce. By the end you will get good idea about some of the features of Screen flows, Auto-launched flows and how to join flows.
Clone Records using Flows in Salesforce
Main takeaways from this Article:

1. How to Clone Records using Flows?
2. How to use Subflow?
3. How to use Radio Buttons in Screen Flow to show object records as picklist/select options. Also, how to use Picklist with picklist options directly from an object's Picklist values in Screen Flow.
4. How to get RecordId and Record details directly from Lightning Record Page into Flows?

Sample Use Case: 
On Account Record Page in Lightning, we need a custom Screen from where a user can quickly create new opportunity by cloning any existing opportunity for that Account. All the fields from the previous Opportunity have to be cloned except for Name,Stage,Close Date which user should be able to provide values for while Cloning.

Also, user should be able to select which Opportunity to clone.

Solution:
To achieve this, we will need to use two Flows.
Firstly, we will Use a Screen Flow to capture user data including which opportunity to clone and also the values of fields mentioned in use case.
Secondly, we will fire a Subflow from the Screen Flow which will just clone this opportunity record.
Note: We will put this Screen Flow on a Lightning Record Page of Account Record.

The overall design will work like as described below (This is the most important piece of this article) :


1st Screen Flow will have a screen where we will provide users with all the Opportunity records(name) for a particular Account Record as Radio Button Options.

User will select one of the opportunity records (using Radio Button) which needs to be cloned.

This opportunity record selected by the user will be stored in a variable with all the field values including Id.
After this we will provide the user with another screen. In this screen user will Input three values. These will be Name,Close Date and Stage. 
Screen Flows in Salesforce
So by now we have the full opportunity record selected by user to clone and three input values.
We will pass these four values (Opportunity Record selected by user with all fields values, New Name Close Date and New Stage Value to a subflow which will just use these values to create a new opportunity for the same Account.

Basically, the idea is we will replace the values of Name,Close Date and Stage in the opportunity record that user selected. Also, we will make this selected record's Id as blank and then create it as a new opportunity record. All other fields will be cloned as we are not changing/overriding their values.


Why we are using Subflow when we can do this in Same flow? 

At first,I also tried to do so. But Basically it doesn't work like that. If we have to use all the values(fields) from a record variable to clone (Opportunity record in our case), we need to pass it to another flow because in the same flow it only copies the value we change not the other ones. This is a thing to remember and note.


Now before moving forward please ensure you understood what we are trying to do so that below stuff makes more sense and can be easily understood.


Please Note: In order to try and showcase a Specific Use Case, I may have overlooked some of the best practises related to Flow Development in this article. Please make sure to follow these in real world scenarios and projects. Check some really important ones below.



Let's dive right into the action and design the Screen flow.

Design of Screen Flow (1st Flow) : This flow will be used to get the Opportunity record to clone from user and user will also provide values of new Name,Stage and Close Date which we need to override in the cloned record. Once we have these values we will just pass them to second subflow, which will create the new opportunity from this data.

Screen Flow will look like this:
Clone Records using Flows in Salesforce
This flow has 4 Elements:

Screen Flows in Salesforce1. Start Element: Create a new Flow of type Screen Flow.

2. Screen Element: Select Opportunity: In this element we are going to present user with the options to Select the Opportunity to Clone for the Account Record that it is on.

Before doing this, we need to know which Account is this screen flow Opened on. Basically, we need to fetch the AccountId and all its field Values to use within our flow from the Lightning Record Page directly.  Cool Stuff!!

How to get Record Id from Lightning Record Pages/Quick Actions directly into the Flow?

Starting in Summer ’20, if you’re configuring a flow on a Record page in Lightning App Builder, you automatically see all record variables available for input in the properties pane. With one tick, you can pass all the record’s values into that record variable in your flow. No more messing with text variable. 
So basically we just need to create an Input Variable on this Flow of type(Record) and whenever we will use this flow on any Record page, all the record details and field values will be passed automatically to this input variable. In our case, we will get all the Account field data including Account Id which we can fetch like recordId.Id.

To create this Input Variable just click on Resource Manager, Click on New Resource and then Select Type as Variable and Data Type as Record. Select object as Account since this is going to be on Account Page. Name this variable as recordId. 
Please note: This variable, "recordId" will have all the account details and fields including Id.
Don't forget to mark this variable as "Available for Input" as this will accept values from Page.

Important Note: This feature is available from Summer'20 release only. In old orgs, you need to first create a text type variable and mark it as input to get the recordId in flow and then use GET Element to get all field values.If you want to try in Summer'20 org directly here is a link to create one https://www.salesforce.com/form/signup/prerelease-summer20/

Checkout the video:

Once we have created this Input Variable, now we can start creating our Screen Element to show all the opportunities for the particular Account so that the user can select one to Clone from.

Using Radio Buttons in Screen: I will be using Radio Button Input option in Screen
Clone Records using Flows in Salesforce
Element to show the Opportunities on Account as Options. For showing options with Radio Buttons, we can directly use a Salesforce Object's records as the Radio Button Options. Also, once user select any radio button using this screen, we can get the selected value/option directly in the variable which we will define for Radio Button Options.

Note in the video, how I found/selected the Opportunities to show in Radio Button options. I used the criteria-" Select those opportunities where AccountId of opportunities equals the AccountId of the record which we will get from Page in the variable recordId.Id. 


Please note: the variable we defined earlier recordId to get Account details from page into flow will have all the account details and fields including Id. To get Id from that we need to use recordID.Id as I did in video

Checkout the video:

Screen Flows in SalesforceBefore we move ahead, please note that in the video, the name of my Radio button choice is "{!SelectOpp}". This is very important as we will now use this variable to get the Selected value (Opportunity in our case) as the value selected by user will be stored in this variable automatically. 

And if you note, in the Record Choice set,I assigned values as Id so basically, the {!SelectOpp} will return to us the Id of the Selected Opportunity. Pretty Cool Right? We will then use Get Element to get all details and field values of this opportunity.
Screen Flows clone records salesforce
Please Watch the video again if this step is not clear.

3. Get Records Element:  In this step, we will just fetch the details of the Opportunity selected by user in previous step. 
As I mentioned, the user selected value will be automatically stored in the variable "{!SelectOpp}". Also, {!SelectOpp} stores the Id of the opportunity and we will use this ID to find all the details of this opportunity. 
Also, at the end we will select the option to store all the values of all the fields for this Opportunity. This is important because now we basically will have access to all the fields of this opportunity. 

Screen Flows Clone Records Salesforce
Please note: The name of my Get Record element was "Opps" . So all the opportunity values will be stored in this variable which we can use later.


4. Screen Element:  To Capture User values for New opportunity: This is a new Screen.In this screen we will just ask user to provide some key values like Name for the new Opportunity which will be cloned, also its stage and its close data values as these values we don't want to clone from old record. Apart from these three values all other fields will be cloned as it is.
Clone Records using Flows in Salesforce

In the screen just add one text input for name, one date input for Close Date and one Picklist Input for Stage Field. Use Picklist values of Opportunity directly here which will come automatically if we create new picklist value set by using Picklist choice set. All these input values will be stored automatically in the names that we will define for the input field/box in the screen and these will be used later to assign values to the cloned record.
Check video to see how to create this:


Now we are done with the First Flow. After this we will use the Subflow element to call another flow to pass all the values from the user and also the user selected opportunity. These two values are necessary to clone this opportunity. 

So let's quickly first create our second flow.

2nd Flow Design: Autolaunched Flow
It will look like this:

Clone Records using Flows in Salesforce
Create Variables to accept Input Values from Parent Flow:

1. We will create 4 variable which will be available for Input as they will be taking input from external Flow.

One Text type variable for Name :{!OppName} This will receive the name entered by the user.
One Text type for Picklist Value of Stage :{!OppStage} This will receive the stage selected by user.
One  Date Type for User Selected Date : {!OppDate} User's submitted date will be received
One Record Type (object = Opportunity):{OppRecord}: for the Opportunity data of the opportunity selected by the user using radio button choice : This will receive the full opportunity data which user selected using radio button.

Please remember we are just creating these variables here but values in these will actually be passed from Screen flow which we will see later. For now assume these variables have values in them.

Just click on Manager on the left hand side tab, and click new resources to create these 4 input type variables. Don't forget to mark them as "Available for Input".

Screenshots:

Clone Records using Flows in Salesforce

OppRecord Variable: To get the opportunity record data from Screen Flow as an Input

Clone Records using Flows in Salesforce
OppDate Input Variable
Screen Flows in Salesforce
OppName Input Variable
Screen Flows in Salesforce
OppStage Input Variable:
Screen Flows in Salesforce








2.Assignment Element: From Parent Flow we will be getting 4 input values into these 4 variables.
We are passing one Record Type variable with all the opportunity fields. In that variable we now just need to replace the value of name, stage and close date. These three values are available in other three input variables which we just defined.
So we will just use one assignment element to basically replace the values of three fields(Name,Close Date and Stage)  in opportunity record variable {OppRecord} with the values that were submitted by the user .

Check above section to recall the variable names.


Very Important:  In the end we will assign the Id of this Opportunity record variable as blank. Since Id is always blank/null before a record is created in Salesforce. So basically we have now created a new instance of an Opportunity record that we need to create/insert.


ScreenShot Below:
Screen Flows in Salesforce


3. Create Record Element: We will just use this element to create new Opportunity record from OppRecord variable.

Please note this opportunity record variable will already have the AccountId since we had fetched this using get all fields data in first flow and it has all other fields value same as that Opportunity except for the ones which we did override on.

We can simply use this variable of Opportunity of data Type Record({!OppRecord}) to create a new Opportunity record with all the same values as old ones except for the fields which we did override on in the last step.

Screenshot below:
Screen Flows in Salesforce
Screen Flows in Salesforce
This is done. Just save this Autolaunched flow and don't forget to Activate it. Remember the name of this flow as this same needs to be selected when connecting from Screen Flow as below



Connecting the two flows :

We just need to go back to our first flow and link it with this flow as a SubFlow.

We will pass the four variable we just created in the Subflow to pass from Screen Flows.
This is how the Screen flow looks like till now:
Screen Flows in Salesforce

To pass the variables we don't need to do anything as when we try to use the subflow they will be recognised and we just need to map them with values from our Screen Flow.


Screen Flows in Salesforce

We will Map the Opportunity Record{Opps} from the Get Record element to the {!OppRecord} variable of the subflow which accept the data type of Record.


Similarly, from the input screen we got three Name and Close Date, which we will map to the three variables of the subflow which we just above.


Checkout the video:



Phewwwwww!!! We are done. Just activate this and use this flow on Record Page of Account.


While adding the Flow to Lightning  Record Page, just check the checkbox where it shows the variable we created to Get the Account Data from the page by the name recordId in the starting. Remember?

Screen Flows in Salesforce

Demo Video Below:




So we have seen how to Use Screen Flows to Clone Records and how to use Autolaunched Flows.


If you like this please do Share! #Learn and Share!


Enter your email address:


Delivered by FeedBurner

Checkout Other Posts :

Comments

Post a comment

Thanks for your Feedback!


Never Miss Latest Posts