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
sgsssgss 

Clone record

Anyy help in this will be appreciated.

Write a Trigger on Account which will create the clone record. (Hint : Map trigger.new to clone record)
Raj VakatiRaj Vakati
trigger asadsd on Account (before update) {
    List<Account> accList = new List <Account>();
    
    for (Account aa : Trigger.new) {
        accList.add(new Account(Name =aa.Name));
    }
    insert  accList;
}
OR 
trigger asadsd on Account (before update) {

    List<Account> accList = trigger.new.deepClone();
    insert  accList;
}

 
sgsssgss
Can you provide test class for this? with all postive negative bulk test case
Raj VakatiRaj Vakati
@isTest 
public class MyAccountcreationTest 
{
	static testMethod void testMethod1() 
	{
		Account testAccount = new Account();
		testAccount.Name='Test Account' ;
		insert testAccount;
		 
		Test.StartTest(); 
			 
			testAccount.Name='Test Account Update' ;
		update testAccount;
		Test.StopTest();
	}
}

 
sgsssgss
User-added image

I am getting this Error. What can be the reason
Raj VakatiRaj Vakati
When you clone the record on after insert -- > your after insert also leads for the another after insert --> which causes number of depaths that are 5 .. 
Raj VakatiRaj Vakati
Try this code
public class P { 
   public static boolean firstRun = true; 
}
trigger asadsd on Account (after insert) {
if(P.firstRun){
    List<Account> accList = trigger.new.deepClone();
    insert  accList;
	p.firstRun = false ;
	}
}

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm