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
sruthi.458sruthi.458 

Apex code Coverage

@istest
public class trg4
{
public static testmethod void testtrg4()
{
account a=new account();
a.name='mohan';
a.billingcity='pune';
a.phone='09885298297';
insert a;
integer cnt=[select count() from account where name=:a.name and billingcity=:a.billingcity];
delete a;

a.name='mohan';
a.phone='09700085852';
a.billingcity='pune';
insert a;
system.assertequals(cnt,1);
}
}

Suresh RaghuramSuresh Raghuram

what is the problem with the test class and where is your class code.

 

It is hard to say where you did mistake with out seeing your class,

 

run your class click on the number of percentage covered, where you can see the blue  and orange are , post the orange are code which is not covered.

sruthi.458sruthi.458

Hi Suree,

 

the code coverage shows like this..

 

trigger trg4 on Account (before insert)
{
for(account a:trigger.new)
{
if([select count() from account where name=:a.name and billingcity=:a.billingcity]>0)

delete [select id from account where name=:a.name and billingcity=:a.billingcity];


}
}

Suresh RaghuramSuresh Raghuram

first thing donot write the soql querys in the for loop because it may hit the governor limits.

 

one more thing is if you give corresponding inputs the if conditions, for loops and most of the times soql querys also comes code coverage.

 

 

If this answers your question make this as a solution.

Jerun JoseJerun Jose

Sruti,

 

Remove or comment the line 'delete a;' from your testmethod. That should handle your code coverage.

 

But just as Suree mentioned, you will need to upgrade your code to improve its standards. Otherwise, it can crash when working for bulk load data.