You need to sign in to do that
Don't have an account?
Nagma Khan
how to solve the test class on trigger ?
hi
its my Class
// trigger that work if account on check box is checked then automatically checked on the contact checked
trigger UpdateContact on Account (before insert, before update) {
List<Contact> contactList=new List<Contact>();
if(trigger.isInsert){
For(Account a: Trigger.new){
Contact c=new Contact(lastName=a.name);
c.Contact_checkbox__c=true;
contactList.add(c);
a.account_checkbox__c=true;
}
insert contactList;
}
if(trigger.isUpdate){
For(Account a: Trigger.new){
List<Contact> c= new List<Contact>([select id from contact where LastName=:a.name limit 1]);
c[0].Contact_checkbox__c=a.account_checkbox__c;
contactList.add(c[0]);
}
update contactList;
}
}
========================================
its my test class how to complete becasue its only coverage 64 %
@isTest
public class UpdateContact_Test{
@isTest
static void tesMethodss(){
account ac=new account(name='test');
insert ac;
contact cont=new contact(lastName='testMethod',firstName='testOne', Accountid=ac.Id);
List<Contact> c= new List<Contact>([select id from contact where LastName=:ac.name limit 1]);
c[0].Contact_checkbox__c=ac.account_checkbox__c;
update c;
}
}
can any one support me ?
its my Class
// trigger that work if account on check box is checked then automatically checked on the contact checked
trigger UpdateContact on Account (before insert, before update) {
List<Contact> contactList=new List<Contact>();
if(trigger.isInsert){
For(Account a: Trigger.new){
Contact c=new Contact(lastName=a.name);
c.Contact_checkbox__c=true;
contactList.add(c);
a.account_checkbox__c=true;
}
insert contactList;
}
if(trigger.isUpdate){
For(Account a: Trigger.new){
List<Contact> c= new List<Contact>([select id from contact where LastName=:a.name limit 1]);
c[0].Contact_checkbox__c=a.account_checkbox__c;
contactList.add(c[0]);
}
update contactList;
}
}
========================================
its my test class how to complete becasue its only coverage 64 %
@isTest
public class UpdateContact_Test{
@isTest
static void tesMethodss(){
account ac=new account(name='test');
insert ac;
contact cont=new contact(lastName='testMethod',firstName='testOne', Accountid=ac.Id);
List<Contact> c= new List<Contact>([select id from contact where LastName=:ac.name limit 1]);
c[0].Contact_checkbox__c=ac.account_checkbox__c;
update c;
}
}
can any one support me ?
Please try below test class
Let us know if this will help you