You need to sign in to do that
Don't have an account?
aress
test class for trigger on account
Need test class for following trigger to create clone of account record after insert.
-------------trigger---------------
trigger CloneAccountTrigger on Account (after insert) {
if(Trigger.isAfter){
if(Trigger.isInsert){
CloneAccountTriggerHandler.cloneAccountRecord(Trigger.New);
System.debug('Trigger');
}
}
}
--------------handler-------------------
public class CloneAccountTriggerHandler {
public static Boolean cloneRecord = true;
public static void cloneAccountRecord(Account[] newAccount){
if(cloneRecord) {
System.debug(newAccount);
cloneRecord = false;
List<Account> listAccount = new List<Account>();
for(Account account : newAccount)
{
Account newCloneAccount = account.clone(false);
listAccount.add(newCloneAccount);
}
Database.insert(listAccount,false);
}
}
}
-------------trigger---------------
trigger CloneAccountTrigger on Account (after insert) {
if(Trigger.isAfter){
if(Trigger.isInsert){
CloneAccountTriggerHandler.cloneAccountRecord(Trigger.New);
System.debug('Trigger');
}
}
}
--------------handler-------------------
public class CloneAccountTriggerHandler {
public static Boolean cloneRecord = true;
public static void cloneAccountRecord(Account[] newAccount){
if(cloneRecord) {
System.debug(newAccount);
cloneRecord = false;
List<Account> listAccount = new List<Account>();
for(Account account : newAccount)
{
Account newCloneAccount = account.clone(false);
listAccount.add(newCloneAccount);
}
Database.insert(listAccount,false);
}
}
}
Please Try this code:-
Please mark as best answer if it helps you.
Thank You
Ajay Dubedi
1) https://trailhead.salesforce.com/modules/apex_testing
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
Sample Test Class for you
Let us know if this will help you