How To: Clone Person Accounts in Salesforce
September 23, 2018
How To: Run Super Clone Pro from Batch Apex
October 26, 2018

How To: Clone a Parent Record with Child Records that Reference Each Other

Click to view Super Clone Pro on the Salesforce appExchange

Cloning hierarchies of records can run into challenges when records in the hierarchy reference each another. Lookup filters can add complexity to logic needed to clone references. Super Clone Pro can help connect record references when cloning a hierarchies of records.

  • If a record references another record lower in the hierarchy, Super Clone Pro will update that parent’s lookup reference field after the child record is inserted.
  • If a child record references a record higher in the hierarchy, Super Clone Pro will set the value of the reference field before inserting.

Below is a use case that includes a Parent-Child relationship with Assortment and Assortment Line objects. In this scenario, the Assortment Line records have multiple record types where one type references the other type of record. The Product Assortment Line records reference a Section Assortment Lines. The lookup field on the Product Assortment Line contains a filter that requires that both Product and referenced Section Assortment Line records to reference the same parent Assortment record.

This structure requires a little extra work to clone because we need the record Id from the Section Assortment Lines before the Product Assortment Lines can be inserted. We will then create the configuration to see the Parent-Child relationship as a Parent-Child-Grand Child relationship.

  • First, create a checkbox formula field on the Assortment Line. The formula should indicate that the record is a Section. The example below has a field called “isParent__c” that is looking for the Parent_Section__c lookup field to be empty.

  • Create a configuration that includes the Assortment Line relationship and Assortment Line used by the Product record type records that reference the Section records.
  • Set the “Filter By” for the Assortment Line relationship that is a direct child of the Assortment to the checkbox formula field. This will tell Super Clone Pro to exclude the product records at this level in the hierarchy.
  • Set the Assortment relationship field in the Product Assortment Line relationship to the “Reference Clone / Clear” Action.
  • Then set other “Sort By”, “Show”, “Edit”, “Required”, and “Display Order” configurations as needed.

Super Clone Pro’s confirmation page should then display the hierarchy as a Parent-Child-Grand Child relationship. The logic will insert the Assortment first. Then the Section Assortment Lines will be inserted with a reference to the new Assortment. Finally, the Product Assortment Lines will be inserted with both the reference to the new Assortment and references to the new Section Assortment Lines.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
Read more