You need to sign in to do that
Don't have an account?

test class for After undelete event trigger
Hai Hall please help me get a code coverage
trigger afterundeletethecontact on Contact (After undelete) {
list<Account>acc=new list<Account>();
for(contact c:trigger.new)
{
Account a=new Account();
a.id=c.AccountId;
a.name=c.lastname;
a.phone=c.phone;
acc.add(a);
}
update acc;
}
testclass
@istest
public class Afterundeletecontacttest {
@istest
static void testme(){
Account a1=new Account(name='jjjj',phone='9999');
insert a1;
contact c=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
insert c;
contact cf=[select lastname,phone from contact where id=:c.id];
delete cf;
contact ce=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
insert ce;
Account af=[select id,name,phone from account where id=:a1.id];
af.id=ce.AccountId;
af.name=ce.lastname;
af.phone=ce.phone;
update af;
system.assertEquals(af.id,ce.AccountId);
system.assertEquals(af.name,ce.lastname);
system.assertEquals(af.phone,ce.phone);
}
}
trigger afterundeletethecontact on Contact (After undelete) {
list<Account>acc=new list<Account>();
for(contact c:trigger.new)
{
Account a=new Account();
a.id=c.AccountId;
a.name=c.lastname;
a.phone=c.phone;
acc.add(a);
}
update acc;
}
testclass
@istest
public class Afterundeletecontacttest {
@istest
static void testme(){
Account a1=new Account(name='jjjj',phone='9999');
insert a1;
contact c=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
insert c;
contact cf=[select lastname,phone from contact where id=:c.id];
delete cf;
contact ce=new contact(lastname='SSS',phone='1111',Accountid=a1.id);
insert ce;
Account af=[select id,name,phone from account where id=:a1.id];
af.id=ce.AccountId;
af.name=ce.lastname;
af.phone=ce.phone;
update af;
system.assertEquals(af.id,ce.AccountId);
system.assertEquals(af.name,ce.lastname);
system.assertEquals(af.phone,ce.phone);
}
}
Please find below modified Test Class which provides 100% code coverage: Let us know if that helps you. Appreciate your response.
Best Regards,
BALAJI
All Answers
Please find below modified Test Class which provides 100% code coverage: Let us know if that helps you. Appreciate your response.
Best Regards,
BALAJI