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
Nagma KhanNagma 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 ?
Amit Chaudhary 8Amit Chaudhary 8
NOTE :- you need to update the account record
Please try below test class
@isTest
public class UpdateContact_Test{
    @isTest
    static void tesMethodss()
	{
        account ac=new account(name='test');
        insert ac;
		
        contact cont=new contact(lastName='test',firstName='test', Accountid=ac.Id);
		insert cont;
		
		Update ac;
		
    }
}

Let us know if this will help you