Use Case: Clone Any Objects with Related Lists with Flow
“Clone with related” is an amazing feature which sadly is still not available on custom objects. No worries! This flow solution helps you to clone ANY objects with ANY related lists, and we only use the easiest steps! Let’s dive into how to make that happen!
* Big thanks to Neal Lightfeldt for sending in the case!
Lulu Mobile uses standard Account, Asset, and Contact objects to track their customers’ information. They also have Account Contact Relationship enabled. The sales reps want to be able to clone the Accounts with the option of cloning either Asset or Related Contact lists or both or none.
The flow is not that complicated!
Please don’t be intimidated by the flow charts. The most essential concepts are just Get Records, Loop, Assignment, and Create Records.
Depending on how many related lists you want the users to be able to clone, we need to repeat steps 7 – 13 for the same number of times. For example, in this case we let the user choose between 1) Asset and 2) Related Contact, so we repeated steps 7 -13 for two times.
In the beginning, we use a Screen and Checkbox Group to let users choose which related list to clone. Then, we use that answer in Decision elements. At the end, we add another Screen to let the user link to the newly created record. We will launch this solution as a Quick Action.
Actual Flow: Clone With Two Related Lists
Structure: Unique Steps Of The Flow
Screen Flow | Assignment | Variable/Collection |
Loop | Create Records | Record Id |
Decision | Get Records | Screen Element |
Does the solution solve your problem? If not, write us what your problem is and we will build the flow for you!
I’ve tried to duplicate//modify this to copy an opportunity and close products, partners, and contact roles…I didn’t clone the original opportunity, because I wanted to put in a new close date and name…It creates the new opp, but the assign element isn’t assigning the new Opp ID, so it’s adding the products to the original opp. Any ideas/
Hi Sonia, how is your newOppId fetching the new opportunity’s Id? (Did you choose manually assign variable in the Create Records?)
Would it work if you use the standard Id variable that is created automatically? (See screenshot)
Two possible scenarios in my mind –
Hope this will help!
I assgned the New Opp Id a variable, added an assignment to the loop to of Current loop ID = New Opp Id, and then added the look to the collection, and created the new from that collection.
Hmm it’s pretty strange. Everything looks alright so far. Can you check a few more things?
Alternatively, you can actually use the Assignment to modify the opportunity variable that you get from the Get Records. (see 3 in scrnshot). You can combine these into step 5, and use that updated variable in Create Records instead of hardcoding it. (The best practice here is actually to clear out the Opp Id, but it still works even if we don’t do it). However what you built looks legit to me, so let’s try to troubleshoot further before we jump to another solution.
This worked perfectly on the first try! It’s rare that I get any PB/Workflow to work correctly the first time around so it goes to show how well written these steps were. Thanks!!
I am really happy to hear that Jonathan!! Good luck with all the future automation building 🙂
Please explain how the original Account ID is being passed into the input variable! Thank you
Hi Cory, I assume you mean how to pass the original Account Id into the variable created in step 4, correct? So step 1 we created a recordId variable. This variable will fetch the record where you launch the flow. Since we put an Action on Account, the recordId will store the Account information, so the original account Id is the recordId.Id. Then in step 5, use an Assignment to assign the input variable as recordId.Id. This will be your original Account Id. Hope this helps!
Hello,
Thank you for this great step-by-step guide! I followed your instructions and was able to create a version of the flow that works perfectly when I run it in Debug mode but does not seem to do anything when I run it for real. Do you have any idea why this might be happening?
Thanks!
Hmmm it’s really strange that this happened. So when you ran in debug, all the records got created successfully? To debug an activated flow, you can set up the debug log in the Setup. Or you can also send me the flow details so we can debug together.
Mccoy, I had the same problem. Have you named the variable as recordId strictly?
Hi, I have the same problem, did anyone find a solution?
Hi Carlos, Juan seems to resolve the issue by checking the recordId api name. If you write down more details of the issue you are facing, we can try to troubleshoot together
I’m another person with the same issue. It is creating records in debug, but doesn’t create anything when I use the quick action button. How can I resolve this?
I have the same issue – action created, tied to a button, flow runs and creates a new record, but without the related lists. When tested in debug, flow runs perfectly – creates the cloned record and related lists. Any ideas? Verified API name as recordID.
Hi Juile,
The record variable is case sensitive. Have you tried “recordId” instead of “recordID”?
This was such an amazing explanation and it worked perfectly, thank you so much. I’ve used it in several use cases already.
One important thing I noticed is that when you clone the record and related records it keeps the original user, owner and created date. So, in the assignment element, it is very important to mute these, otherwise you might run into some data quality issues later.
Thanks, Miranda. It is nice to hear that! Also really appreciate you sharing your findings with the community :)!
I have a similar use case. I need to clone a record with one related list (what you did) but then i need to add this newly created record to (for example) 50 accounts.
Is there a way to reference the newly created record with the related records and then add that record to multiple accounts?
Hi Jan,
Let’s discuss how should we achieve this! When you said “add the record to multiple accounts”, what did you mean by “add”? Is there a lookup on the Account object and points to the object of this record, and you want to populate that lookup using this record?
I have use case like this
A,B,C 3 objects
C is child to B
B is child to A
A is having quick action button
When I click this button, then i should clone all A and related B and it’s related C records and should creat new records
With your flow explanation I can able to creat A and it’s related B records. But I am getting error while creating C records.
Whatever the C records are creating,those are linking to original B records not to clone B records.
How to resolve this
Hi Zahed, three levels will become quite complex, so for this I actually suggest using Apex. You can leverage some Apex actions listed on unofficalSF such as in this post: https://unofficialsf.com/list-actions-for-flow/
(There could probably be a workaround with flow, but it’s not going to be a pretty one)
Hope this helps!
Based on your flow only I achieved third level also. And my flow working properly. Am able to get related records of child records
Hi Zahed,
I have exactly the same use case.
I actually have 4 levels.
Have you been succesful using only flow builder or did you use Apex?
Thank you so much Melody ! Your solution is absolutely great ^^
Hi, thanks for the post. However,when trying to adapt your flow to my business case (i.e. clone Campaign with Members) I face the following problem: in step “8 Repeat ” you create a “Account Contact Relationship” variable type, which does not seem to have an equivalent for Campaign + Members. I’ve used “Campaign Members” instead, but the flow thorws an error: “DUPLICATE_VALUE: Already a campaign member”. Any suggestions?
Thanks!
Hi Fabrizio, it sounds like the reparenting is not successful so the system was trying to parent the new campaign members to the old campaign. Try to make sure the new campaign is created, and in the loop, all the campaign member’s campaign Id is updated to the newly created record. Hope this helps!
Fantastic resource, cannot thank you enough. With my first flow, I was able to get a critical business process automated using this article, diagram and steps (I recognize a fellow systems and documentation nerd :). Thank you!!
One question I still have: Although I believed I had put the Create Records element outside of a loop (see screenshot), I am still getting the “tip” that says the following:
“Remove Database Access from Loops: A loop contains a/an Create Records element. To avoid reaching per-transaction flow limits, move the “Create New Module Seat” element outside the loop, and have it act on a collection.”
Does anyone know what I need to do here?
Hi Sarah, thanks for the nice words! It seems like your first loop is not closed (I can’t see the “after last item” path is used in the first loop?), so the system would think the Create Records is still in the first loop. If you configure that correctly, I believe the suggestion will disappear. Hope this helps!
Hi Melody, thanks for an awesome article. I just created a flow to clone campaign members. It worked like a charm.
That’s great to know Ruby! Thanks for your kind words:)
I’m unable to get the newly created recordId somehow its redirecting me to the original record id itself. Can you help?
Hi Lucky, if you configure the steps exactly like 5&6, then you should be able to get the new Id from recordId variable. Make sure you follow those steps thoroughly, and if it still doesn’t work, feel free to send the screenshots to me for troubleshooting.
Hello Melody, this guide works perfectly, I’ve successfully used it to clone quotes & quote line items. I’ve added this as a custom action to our lightning experience pages, however I would also like to add this as a button. I’ve created a button with a url that links to my flow but when I click on it it goes through the whole checkbox process and then when I click finish, it doesn’t actually clone the quote and just brings me back to the beginning of the flow. I’m guessing that the original quote variable isn’t get passed into the flow correctly.
I would also need the finish button to not bring you back to the flow beginning, but close the pop up window.
Could you offer any assistance here?
Hello! So you can take a look at this article to check if you have configured the button correctly:
https://salesforce-flowsome.com/flow-how-to-use-record-id/
For the finish behavior, unfortunately it is impossible to force closing the window, however you can add a final screen to ask people to close it, and remove the “FINISH” button. This way they won’t be redirected back to the start of the flow.
i keep running into below error when i debug the flow. it happens at the related list create record step. not sure how do I resolves this. there are no duplicates or duplicate rules in place
Error Occurred: This error occurred when the flow tried to create records: DUPLICATES_DETECTED: Use one of these records?. You can look up ExceptionCode values in the SOAP API Developer Guide.—This error occurred when the flow tried to create records: DUPLICATES_DETECTED: Use one of these records?. You can look up ExceptionCode values in the SOAP API Developer Guide.—This error occurred when the flow tried to create records: DUPLICATES_DETECTED: Use one of these records?. You can look up ExceptionCode values in the SOAP API Developer Guide.
Hi Sumit, this to me really looks like a duplicate rule error… could it be that the duplicate rule is on another object, and the current object is somehow affecting that one? If this is not the case, suggest to reach out to Salesforce support.
Hi Melody! Thanks for your awesome instructions. I’m having trouble (accidently replied to a users comment below – wrong place) with my action. The flow works perfectly in debug – creates the cloned record and related list. However, when the action executes (from the button tied to the flow), a new record creates without the related list. Any ideas why the action is firing up but not copying the related list? I did verify the API name as recordID. Thanks in advance!
Hi Juile,
The record variable is case sensitive. Have you tried “recordId” instead of “recordID”?
I had the same exact use case to clone the parent record along with its related records. Everything works exceptionally well. But Why does the cloned record shows the record id instead of a record name?