Clone Records Using Flow

In this blog you will learn how you can clone multiple records easily. In this example we will clone accounts.

Use Case :
Ask the user if they are ready to clone the accounts and then clone all the accounts using flow.

Step 1 : First we will create a screen flow and add a screen element on that which will ask the user if they are ready to clone the accounts.

Have a look :

Step 2 : Take get records element to get all the accounts from the database.

Have a look :

Step 3 : Now we will Loop through the accounts to clone them. Let's take loop element for that.

Here it is : 

In this loop we just need to add our collection variable name which have all our accounts and in this case we will put our Get Record Element name which is "get_accounts".
After that we will not add Create Record Element inside loop because it is not advisable to use DML inside Loop.
So, what we will do is. We will take a variable of Record DataType to save the account in that.

Step 4 : Take a Record Type Variable and name it "accountdetails". In Object option select Account.

Have a look :

Now, when we will loop through the accounts we will assign the account values to this variable. For that we will use Assignment Element.

Have a look :

In this Assignment Element we will assign values from loop to our variable "accountdetails". So here in accountdetails>Account Name we are putting LOOP>Account Name.

Yeah! I know this is a bit tricky but just stay focused and you are going to learn a very useful example. ✌

Okay! So far So good.

Let's have a look at our flow till now.

Step 5 : After assigning account to a variable we need to assign the variable to a collection variable. Why? because when the loop which go to the second record then the second record will replace the first one. Which means at the end of the Loop you will be left with only one account record in the variable.

We will take a collection variable and add our "accountdetails" variable to that collection. So with this every time loop will process each account will be added to our collection variable.

Here is the collection variable with name "AccountCollection". Just notice that for collection variable we have tick the "Allow multiple values" checkbox.

Now, let's take an assignment element and assign "accountdetails" to "AccountCollection".

Here, we have taken an assignment element and in Variable section we are adding "accountdetails" to "AccountCollection".

Almost there!

Step 6 : After Loop Last Item add a Create Record Element to finally create all the accounts which are saved in "AccountCollection" variable.

Have a look :

Here we have just taken Create Record Element and in Record Collection Option we will put our collection variable name which is "AccountCollection". That's it we are done.

Now let's just show success screen to the user that your work is done. 

Here is the screen :

This is how your flow will look :

Give a tap on your back for completing all these steps. Good Job. 👍

For details video on understanding all these steps, Do check out the video below :

If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Let's learn and grow together.
Love and Peace! 🧡

Post a Comment