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
Jeff Bryant 16Jeff Bryant 16 

Cloning Records via Apex

Is there a simple way of mass cloning a record for testing purposes?
I was thinking of executing anonymous with something like...

Loan__c loanObj = [SELECT Id, Name, Status__c FROM Loan__c WHERE Name = 'L-1983549'];
List<Loan__c> loanList = new List<Loan__c>();
for(integer i = 0; i < 10; i++){
Loan__c loanObjClone = loanObj.clone(true);
loanObjClone.Name = 'loanObjClone ' + i;
loanList.add(loanObjClone);
}
insert loanList;
AnudeepAnudeep (Salesforce Developers) 
Hi Jeff, 

I recommend the solution listed here

Let me know if it helps