Clone Records with their Related records in Salesforce using Flow

In Salesforce, record cloning is required to manage business processes, from sales to customer service. Salesforce provides a basic feature for cloning records and their related records, but with the help of flows, we can automate the process of cloning records with their related records.

In this Salesforce tutorial, we will learn to Clone Records with their Related records in Salesforce using Flow. Below image is the reference of the Screen flow that we will create to clone the Account record with its contacts.

Use Screen flow to Clone Salesforce Account with associate contacts

Deep Cloning in Salesforce

In Salesforce, the term Deep cloning is used when we clone the records along with their related records, for example, cloning an Account record with its Contacts or cloning an Opportunity record with the Opportunity members.

This deep cloning of records can be done manually and with automation using the flows.

Clone Records with their Related records in Salesforce using Flow

We will create a Screen flow in the following steps to Clone Records with their Related records in Salesforce.

1. Navigate to the flow builder

Navigate to the Setup page, go to the Quick Find box, and search, then select Flows under the heading Process Automation.

  • In the Flow setup window, click on the button New Flow.
  • Select the option Screen Flow and click on the Create button.
Clone Records with their child records using flow in Salesforce

2. Screen element for user confirmation

Now, we will add a Screen element to the flow that requires user confirmation to clone related records, such as the contacts of the current Account record.

See also  Create Record Trigger Flow in Salesforce | What is Record Trigger Flow in Salesforce

Enter the Label and API Name for the screen element and add a Display text component to the screen.

Salesforce Record Cloning with Screen Flow

3. Create a Resource to fetch the current Account Record

To clone an account, we need its ID, so we will create a resource that gets the ID of the current account record. Create a New resource with the following details.

  • Select the Resource Type as a Variable.
  • Enter the API Name as recordId ( it must be ‘recorId‘ only)
  • Select the Data type as Text.
  • Activate the checkbox available for Available for Input and click Done button.
How to clone Salesforce Accounts with their related contacts

4. Add a Get record element to get the account

After this add a Get record element to the flow and the following fields in that.

  • Enter the Label and API Name for the get record element.
  • Select the Object as Account.
  • In the Condition Requirements, select the Field as Id, Operator as Equals, and Value as recordId.
Clone Accounts with associated contacts using flow in Salesforce

5. Add a Screen element to override the Account name

Now, we will add another Screen element to override the account name of the cloned record. Enter the Label and the API Name for the screen element.

Add a text element to the screen, labeling it Account Name. The API Name will be auto-filled according to the entered label. Then click on the Done button.

Use Screen flow to Clone Salesforce Accounts with their Contacts

6. Add Create Record element to Clone Account Record

  • Below the Screen element, add a Create Record element to the flow. Enter the Label and the API Name. After this, activate the radio button ‘Use Separate Resources and lateral values,’

In the Object field, select the Account object.

Use Salesforce Flow to Clone Accounts with associated contacts
  • In the section, Set Field Value for an account, map the Name field with Account Name (text) and Phone field with Get_record > Account Phone.
Clone Account record in Salesforce with associated contacts
  • Manually activate the checkbox, assign a variable, and select New Resource in the Variable field.

Enter the below details for the new resource.

  • Select the Resource Type as a Variable.
  • Enter the API Name as Id_of_cloned_account.
  • Select the data type as text and activate the checkbox available for input.
  • At last, click Done.
How to clone Salesforce records with their related records

7. Get Record element to fetch Related Contacts of an Account record

To fetch the related contacts of account records, add a get record element to the flow. Enter the below details in the Get record element.

  • Enter the Label and the API Name for the get record element.
  • Select the Object as Contact.
  • Then, in the condition requirements for fetching the Account of Contacts, select the Field as AccountId, Operator as Equals, and Value as recordId.
Clone Salesforce Records with their related records using flow

8. Loop element to fetch all related records

The get record element will only fetch a single contact record; to fetch all associated contacts, we will add a Loop element to the flow.

See also  How to Use Lightning Email Templates in Salesforce Flow

Enter the Loop element’s Label and API name. In the Collection Variable, select the get record element we created to fetch contacts.

Clone Account record in Salesforce with their contacts using flow

9. Create New Resources to store variable

The loop element will fetch single records in each loop, so first, we will create a resource variable to store a single variable, then we will create a collection variable for the Assignment element.

New Resource for single variable

Create the new resource with the following details.

  • Select the Resource Type as a Variable.
  • Enter a relevant API Name for the resource.
  • Select the Data Type as Record and Object as Contact.
  • At last, click Done.
How to clone Salesforce Accounts with their contacts

New Resource for collection variable

Create another resource for the collection variable, with the details as follows.

  • Select the Resource Type as a Variable.
  • Enter the API name for the resource.
  • Select the Data Type as Record and Object as Contact.
  • Activate the checkbox Allow Multiple Values, and click the Done button.
Clone Salesforce Accounts with Associated contacts using flow

10. Add an Assignment element for a single variable in the Loop (for each)

Add an Assignment element with the help of which we will assign the first contact that loop is iterating to the single resource variable we created.

Enter the Label and API Name for the Assignment element. After this, map the following Variables with their values.

Variable Value
SingleContactRecord > Account NameClonedAccountId
SingleContactRecord > First NameCurrent Loop item > First Name
SingleContactRecord > Last NameCurrent Loop item > Last Name
Use Salesforce Flow builder to clone accounts with related records

11. Add an Assignment element for the Collection variable in the Loop (for each)

Add another Assignment element to create a collection variable of fetched contacts.

Enter the Label and API Name for the Assignment element. In the section Set Variable Values, select the Variable as ContactCollection (collection variable), Operator as Add, and Value as SingleContactRecord (single variable).

Create a clone of Salesforce Account with related contacts using flow

12. Create a Record element for Clone Account with related contacts

Finally, add a Create record element and enter the Label and API Name for the Create Record.

In the option to create records, select Multiple.

See also  Salesforce Orchestration Flow | Create Record Triggered Orchestration Flow in Salesforce

In the Record Collection, select the record collection that we created for contacts.

Use Salesforce screen flow to clone records with their related records

Finally, we will add an optional Screen element that displays the message of a successful clone.

13. Save and Activate the flow

At last, save the flow by entering the Flow Label and Flow API Name, then click the Save button.

Clone related records using flow in Salesforce

Click on the Activate button to activate this flow.

Deep clone records in Salesforce using flow

Now, the flow is created and activated, and in the further steps, we will test and debug the flow.

Test the created Screen flow

To test the flow, we will create a quick action to call the Screen flow.

1. To create the quick action, navigate to the Object Manager and open the Account object.

Clone Salesforce Accounts with related records using flow

2. In the Account object, click on Buttons, Links, and Actions. Then, in the next window, click on New Action.

Use Salesforce screen flow to clone Accounts with contacts

3. Enter the below fields, to create a new action to call screen flow.

  • In the field Action Type, select the option Flow.
  • In the Flow field, select the flow that you have created.
  • Enter the label for the New Action button and the API Name will be auto-filled. In this case, I have labeled it as Deep Clone.
  • At last, click Save.
Add quick action to call flow for cloning records in Salesforce

4. Navigate to the Page Layout of the Account object in the object manager, then open the default page layout, and from the Mobile and Lightning Action, drag and drop the created action ‘Deep Clone‘ to the region Salesforce Mobile and Lightning Experience.

At last, click Save to apply changes.

Use Screen flow to Clone Salesforce records with related records

5. Now open the Account record that you want to clone, and in the quick action tab, click on Deep Clone (created quick action).

6. In the first screen, click Next to confirm the clone, and on the second screen, write the name that you want to override for the cloned account.

Clone Salesforce Records with child records using flow

7. The current account record and associated contacts will be cloned now. Click the Finish button to complete the flow.

Clone All related records of a record using flow in Salesforce

8. Now open the cloned account record, and there you will see the associated contacts.

Here, we can see that the Account record is cloned successfully with its associated contacts.

Use Salesforce flow automation to clone related records

In this way, we can Clone the Records with their related records in Salesforce using Flow by following the above steps.

Conclusion

In Salesforce, using flows, we can automate the cloning process of records and their associated records. By implementing this automation, we can save a lot of time by avoiding the manual cloning of records, and it clones the records without any errors.

By following the above steps, you might have understood the process of cloning the records with their related records in Salesforce using Flow.

You may like to read: