function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RadnipRadnip 

Cloning from SOQL (with child records/objects)

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

 

SELECT
    X,y,z,
    (SELECT
          a,b,c
      FROM
          Contact)
FROM
Account
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).

 

Thanks

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.

RadnipRadnip

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.