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
ChinnoduChinnodu 

i have written a test class but i got code coverage 65%, i need more than 75%.

HI Experts,

i have written a test class but i got code coverage 65%, i need more than 75%. kindly help me on this.
 
@istest
public class AccConUpd_test
{
 static testMethod void testMethod1() 
 {
 
 Account testAccount = new Account();
    testAccount.Name='Test Account' ;
    
    insert testAccount;
 
 Contact cont = new Contact();
        cont.FirstName='a1123';
        cont.LastName='rest';
        cont.Accountid= '0019000001xfaMI';
        cont.Employee_Id__c='1091637612';
        cont.PAN_Number__c='apgffg';
        cont.Working_Days_Per_Week__c=7;
        cont.Phone='12344';
        
        insert cont;
 }
}

User-added image


Thanks!

Sai
Naveen Kumar B H(bhns)Naveen Kumar B H(bhns)
Hi Sai,

You don't have to cover a trigger more than 75%. Check below salesforce document.
https://developer.salesforce.com/forums/?id=906F000000092bjIAA

If you really want to cover more than 75%, replace your test class code as below.
 
@istest
public class AccConUpd_test{
	static testMethod void testMethod1(){
 
		Account testAccount = new Account();
		testAccount.Name='Test Account' ;
    
		insert testAccount;
 
		Contact cont = new Contact();
        cont.FirstName='a1123';
        cont.LastName='rest';
        cont.Accountid= testAccount.ID;
        cont.Employee_Id__c='1091637612';
        cont.PAN_Number__c='apgffg';
        cont.Working_Days_Per_Week__c=7;
        cont.Phone='12344';
        
        insert cont;
		
		testAccount.Phone='9800021112';
		UPDATE testAccount;		
	}
}



Regards
Naveen 
ChinnoduChinnodu
Hi Naveen,

Thanks  for your help.

But how  below lines coverd, can you please suugest on this. hoUser-added image

Thanks,
Sai
Naveen Kumar B H(bhns)Naveen Kumar B H(bhns)
Hi Sai,

I hope current code coverage is 100%. 

As per your screen shot you are code is trying to query Contact records which are child records for Account. 

In your previos code you were hardcoded Account record Id when you are creating contact record in test class.
cont.Accountid= '0019000001xfaMI';

But that record id will not exist when you are running test class.May be that erecord id exist in your org, but to see the record of your org in test claas, you should define as Seel all data = true in your test class.

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

Or you should create test data in your test class. you are already doing that.

Let me know if you need more information.

Regards
Naveen
Naveen Kumar B H(bhns)Naveen Kumar B H(bhns)
Hi Sai,

If your problem is solved, mark resective answer as best answer.