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
nilesh walkenilesh walke 

nilesh walke Write a Trigger on Account which will create the clone record for test class


trigger CloneARecord on Account (After insert) {  if(cloneHandler.runOnce()){​​​​​​​  
      list<Account>Accounts = new list<Account>();  
      for(Account record: trigger.new){​​​​​​​             Accounts.add(record.clone(false,false,false,false));
        }​​​​​​​
        if(Accounts.size()>0){​​​​​​​
            INSERT Accounts;  
      }​​​​​​​     }​​​​​​​
}​​​​​​​

[05-05 12:45 pm] Nilesh Walke
public class cloneHandler {​​​​​​​​
public static boolean run= true;
public static boolean runOnce(){
​​​​​​​​ if(run){​​​​​​​​ run=false; return true;
}​​​​​​​​
else{​​​​​​​​ return run;
}​​​​​​​​ }​​​​​​​​ }​​​​​​​​

test class for it
CharuDuttCharuDutt
Hii Nilesh Walke
Try Below Code
@isTest
public class unitest {
  @isTest
    public static void unittest(){
     
        list<Account>lstAcc = new list<Account>();
        For(integer i=0;i<5;i++){
            Account acc = new Account();
            acc.Name = 'testAcc ' + i;
            acc.Phone = '123456789'+i;
            lstAcc.add(acc);
        }
        insert lstAcc;
            }

}
Please Mark It As Best Answer If It Helps
Thank You!