Make identical copies of all records in a model?

I am trying to use the action framework to create a new record based on an existing record. On a single record basis, this is easy, but I need to do it in mass with a single button push. There would only be maybe a dozen records in the model that the operation would work on, but I need carbon copies of each of the 12 records created as new records in the same or another model. I tried “Adopt Rows”. I can’t seem to find much documentation on it, but from what I can see it seems that if the source record is saved, then it has an Id. If it has an Id, then the Adopt Rows function will merge it with existing rows instead of creating new rows. Is there any way to accomplish what I am trying to do with action framework?

This can be done in a couple steps. First the setup.

  1. Create a model to adopt the selected rows into. Call it “AdoptRowsModel”.
  2. Create a model with “Clone Always” and a condition where Id in Id of “AdoptRowsModel”. Call it “CloneModel”.
Now, the mass action action framework.
  1. Adopt Rows into “AdoptRowsModel”
  2. Query “CloneModel”
  3. Save
Done. :smiley:

Pat, you are awesome. I haven’t tried this yet, but I will. In the meantime, I came across this post which uses a java snippet. I modified it for my models and the fact that I want to iterate through the source model records for my each statement instead of a third model like contacts. I ran a test and it works, except I would have to map every field I want copied into the new model. Yours sounds much faster, but the following does work as well. Page Not Found — Skuid v15.1.6 Documentation Thanks for your help.

HA! It worked! Thanks Pat! Never thought to use clone always in a separate model. Nice piece of skuidery!

Yup. The “Clone Always” is quite powerful. You can additionally set a chain of models to clone in same way. Think of an Account with it’s Contacts, Opps, Quotes, Quote Line Items, etc. The whole thing can be duplicated using action framework.

Yes, that is actually what I am doing, but when you clone the children (like contacts) they are cloned with the existing Account. At what point in the action flow do you introduce the change of account on all children contacts? I have tried a couple of things, but can’t get my children to switch parents. I made sure that the master/child relationship is set to reparent.

You should be able to use the method, so long as you query all models in the one query action.

Sorry to be a pain, but what method of updating the parent account would you recommend? 1) model action on the clone always model triggered by requery? 2) a condition on the clone always model set to have the account ID set to the newly cloned account? 3) Other? As always, thanks for the help

I’m not sure I understand. If you set two models,Accounts & AccountContacts, to query with “Clone Always”, then both set of records will clone. The Contacts will be set to the new cloned set of accounts.

Ah, that is where I was missing something. I used a create new on my top level object and then the adopt rows and clone always on the children. I have been unable to get any mid stream changes to stick using update fields on rows. I’ll try cloning the top level ands see if it solves my issue. Thanks!

Finally got back around to this. I added a model action on the clone always model to update fields upon query. This allows me to clone MOST of the original but change a few fields in my clones. Thanks for the help with this! Works great!

Bringing this back from the dead. And right after Halloween! @Skuidward_Tentacles, I was wondering if you could elaborate a bit on your last post about updating some fields and how to set the model action (initiating event and associated actions). On my page, there are a few date fields in the cloned records that need to be updated to Date+1 year. There are some other fields that need a new default value set. Any additional guidance is much appreciated!

Wow! That was a while ago…. As memory servers, when you use the clone always setting, upon query of the model, it creates clone records of all records returned by the query. So simply the query model action on a model set to clone always will create the clones. Then, you can used the update rows action and set it to update all rows in the model and pick the relevant fields.
Now there is a twist because you need to calculate the date that you want to update those fields to and date fields only accept data in a certain format.
To do this you may want to create a UI only model that has a formula field set to output style of date. Get that field to calculate your date value correctly. Once you get it calculating correctly, you can use that value as the update value for your cloned record date fields.
If the date values are specific to each row, then you would need skip the UI only model and instead create UI only fields on your closed model that calculate the date based on a date field from your clone model.
Either way, once you have a valid calculated date, then you can add a model action to your clone model that says “upon query update all rows in the model for the date field using this calculated value from this other field.”
Or, you could use an on page load action sequence yo query the model then update all rows in the model.

Hope that sets you off in the right direction.

Thanks for the reply @Skuidward_Tentacles! I got it working!
Last question. For cloning a child record, I understand the part about having separate models that “Clone Always” and querying them in the same action. Where do I save the cloned child data? Do I also need to have separate AdoptRowsModels for each child object and call that in the same Mass Action before the query?

For example, I’m cloning Grant Request records. Each Request has a scheduled Payment (child object). I have no issues cloning the Requests but how do I also clone the existing Payment and make sure it’s linked to the newly cloned Request?

I never ended up building that aspect out. I know @Jeanguy_Vachon did. Maybe he can shed light on it. I think it was something simple like if you query all the parent and Children models as clone always in the same action and save all the models in the same action, they “remember” where they should go some how.

@tmac Hmmm… this would be challenging. The issue is setting the Lookup value the newly cloned Request (parent) for each newly cloned Payment (child) as the clone always function doesn’t account for this. For sure can be done with some javascript and/or flow. Is the lookup a lookup or Master-Detail?

Hi Pat. Thanks for reaching out. It’s a Master-Detail.

Ok.

  1. New fields on objects. Cloned_ID__c and Cloned_Parent_ID__c (where applicable).
  2. Action Framework to set above custom fields prior to cloning function.
  3. Salesforce Flow to use above fields to update Master-Detail relationships in child records.

Clear as mud?

@tmac Did it work? Any questions?

Hi Pat. Sorry, I’ve been at a conference all week and haven’t had a chance to work on this. I’m hoping to get to it soon and will keep you updated. Thanks for all the help!