New Collection Action: DeepClone
It’s not very hard to clone a collection of records in Flow. You’ve been able to do it in Assignment node for a couple of years, and the Copy Collection action in Collection Processors is extremely efficient. A lot of cloning, however, requires that child/related records get handled as well. This new DeepClone action can really accelerate and simplify flow that do this kind of administrative work.
This action takes as inputs:
|SObject inputRecord;||You can provide either a record or a recordId. You have to provide one and only one.|
|String inputRecordId;||You can provide either a record or a recordId. You have to provide one and only one.|
|List<String> childRelationships;||Provide the names of the child relationships you want to clone. You can provide them either as a collection of Strings or a single comma-separated string. See ‘Specifying the Child Records’ below.|
|String childRelationshipsCSV;||Provide the names of the child relationships you want to clone. You can provide them either as a collection of Strings or a single comma-separated string. See ‘Specifying the Child Records’ below.|
|Boolean saveImmediately = true;||If set to true, the action will immediately save the cloned records. true by default. This needs to be true in order to clone child records because they need a parent recordId or you won’t be able to save them later.|
|Boolean saveChildRecordsAutomatically = false;||Save the child clones immediately along with the parent clone.|
Specifying the Child Records
Using either a List of Strings or a comma-separated string, provide the Child Relationship Name of the child records you want. For example, if you want to clone Opportunity Products along with an Opportunity, you would use ‘OpportunityLineItems’, as shown below:
How it Works
The action creates a clone of the provided input record and immediately saves it so it can obtain the new Id of the newly created clone record. The child records are then retrieved and cloned, and the new Id is used for their lookup value. The child records however are not immediately and automatically saved, as many use cases will call for them to be modified first. Use Create Records to save the child records and Update Records to save any changes to the cloned Parent record.
The action will attempt to append “Clone” and a date to the Name or Subject of the record being cloned so you can distinguish between clones in the event you don’t manually change the record name yourself.
When working with master detail objects. Make sure to add ” __r” to the end of the relationship name. This is very important thing for custom fields and custom relations;
For example, you have a child object with a MD field that references Account. Then in Master Detail Options you can see that for the custom field, Child Relationship Name = Custom_Object_MD_Account. So in Deep Clone set childRelationshipsCSV = Custom_Object_MD_Account__r .
Install via Collection Actions