How to Clone the Record With Related List in Salesforce

To create similar records in Salesforce, we have an option to clone that specific object record using the Clone quick action. But it does not clone child records in a master-detail relationship, such as an Opportunity that has Opportunity Products and Quotes.

In the Accounts object, you will get the option to clone the related records using the “Deep clone” button, but it is not available in other objects.

Let’s see what process we need to follow to enable the settings that allow us to clone the record with the related list in Salesforce.

Clone the Record With Related List in Salesforce

Related list records are the child records connected to a parent record and shown in the Related Lists section on a record’s detail page. To clone child records, we have the “Clone with related List” feature, but it only supports standard objects like Opportunity and Campaign.

For custom objects or complex relationships, we require customization using Apex triggers and Flows to clone records along with their related records.

You can check out this solution to clone the related records using flow in Salesforce.

In the examples below, we will see the methods to clone records with related list records. The first approach is using the standard button in the user interface, and the other is programmatically using Apex code.

  • Clone Record With Related List Using Standard Button in Salesforce
  • Clone Record With Related List Using Apex Code

Using Standard Button in Salesforce

For the standard Salesforce object, we can clone the related records using the standard button Clone with Related.

Let’s see how to add the standard Clone with Related button to the record page to clone the record with the related child records.

  1. Navigate to Setup > Object Manager > select object (Opportunity), then select Page Layouts in the side bar.
How to clone recods wirth related lists in Salesforce
  1. In the page layout setup, click on the Mobile & Lightning Actions tab. Select the action Clone with Related” and drag it to the section Salesforce Mobile and Lightning Experience Actions.

After this, click save to apply the changes.

Clone Opportuniites with related records
  1. On the record page, you will see the button Clone with Related in the quick actions. As we click on it, a pop-up window, Clone with related records, will appear.

In this, we can select the related records to clone with the current records by activating the checkboxes.

After selecting the related records, click Next.