+ Start a Discussion

Cloning from SOQL (with child records/objects)

Rather than cloning an individual object can you clone everything from SOQL? eg if the SOQL is:


WHERE BillingCountry = 'United Kingdom'


Can you clone the account as well as all the contacts without the need to loop through all the contacts everything?


If you do need to loop over the child records whats the best strategy for not hitting DML calls? as wouldn't I need to insert the account first so I can figure out what the ID was to link the contacts? I could then add all the contacts to a list before submitting but the issue I have is I have 4 objects all joined together that I need to clone (all master-detail in one way or another).



Jerun JoseJerun Jose

I am not sure if this will be of any help, but isnt there a clone method available on most objects?

From the documentation I recall there is provision for deep clone as well, where the child records are also cloned.


I have not tried the clone method myself, let me know if you find any use for it here.


Clone only clones the record and not the children

Deep clone can clone the IDs and autonumbers etc..


They are no help for cloning child records unfortunatly.