+ Start a Discussion
sales force 48sales force 48 

apex code for Clone of parent records along with child records

Hi Guys,

I have a fucntionality where i will get list of accounts to be cloned

for example 
List<Account> lstacc=[Select id,Name from Account];

when i clone all the accounts records its corresponding child records also should get cloned and inserted into new cloned accounts,

Can anyone give me the piece of code.

URGENT!!!!!!!!!!!

 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi,

To Clone parent records along with child records Please refer the below link for reference. I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar
Raj VakatiRaj Vakati
Use this code .. it will solve your problem 
 
List<Account> originalList = [Select Id, Name From Account];
List<Account> cloneList = originalList.deepClone();
insert cloneList;