I've seen some tools like Super Clone that can do deep clone (aka clone child records), but what I am looking for is a tool that clones record and then reparents the child records.

I've seen there are some code examples, but I am trying to avoid using that before I've asked the community.


  • There's no OOTB functionality, if that's what you're asking. Use code.
    – sfdcfox
    Jul 21, 2014 at 16:31

2 Answers 2


Did you look at iClone app? IT will allow you to clone child records and re-parent as well. You can do field over-rides as well.

Link: https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B39tWEAR

  • 1
    Not free. I wouldn't be comfortable paying more than $1 per month.
    – dzh
    Jul 25, 2014 at 11:48

So I've solved the problem with a little piece of code. I hope it helps you too.

I've renamed references from my org so there might be error here and there, but I think you'll get it. Also, I have no testing class for it.

Here's the extension class code:

public class cloneAndReparent {
    Public      List<sobject>           selectedRecords      {get;set;}  
    Public      parent_object__c        newRecord           {get;set;}  

    public cloneAndReparent(ApexPages.StandardSetController controller) {
      mycon = controller;
      selectedMeters = mycon.getSelected();
    ApexPages.StandardSetController mycon;
    String recId = ApexPages.currentPage().getParameters().get('id');

    public PageReference ReparentRecords(){
        parent_object__c recToClone = [select id, name from parent_object__c where (id=:recId) limit 1][0]; // note that you will have to select more fields in order them to be cloned!
        parent_object__c newRecord = recToClone.clone(false, false);
        insert newRecord;

        list <child_object__c> childrenToReparent = [select id from child_object__c where id in: selectedRecords];    
        for (child_object__c child: childrenToReparent){
        try {
             update childrenToReparent;
        } catch (DmlException ex){
        PageReference newURL = new PageReference('/'+newRecord.id);
        return newURL;        

And here's Visualforce page:

<apex:page StandardController="parent_object__c" extensions="cloneAndReparent" recordSetVar="records" action="{!ReparentRecords}" >
  • Keep in mind that many Detail objects cannot be reparented, and must be deleted and recreated. For example, Attachments cannot have their ParentId changed. Jul 31, 2014 at 23:59
  • That mostly applies to standard objects, doesn't it?
    – dzh
    Aug 1, 2014 at 8:45
  • Custom objects may work this way as well, depending on whether there is a Master-Detail relationship and how it is set up. If it's just a simple custom Lookup relationship, there wouldn't normally be a problem with reparenting. Aug 2, 2014 at 15:59
  • Just to be clear - there is a checkbox that enables reparenting, regardless of relationship type.
    – dzh
    Aug 5, 2014 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .