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
SFD SalesforceSFD Salesforce 

can any one help me the test case of trigger if else condition

Hi,

 

This My trigger class,

 

global class FBR_ApexScheduleMonthClass Implements Schedulable
{
global void execute(SchedulableContext sc)
{
ValAdd();
}
public static void ValAdd()//Set<Id> InquiryId
{

List<FBR_Inquiry__c> Inquiry= [SELECT KPIInquiryContent__c,CommodityName__c,ModifyDate__c,Status__c from FBR_Inquiry__c ];
{
FBR_Inquiry__c FBR= Inquiry[0];
Date startDate=FBR.ModifyDate__c.toStartOfMonth();
Date endDate=FBR.ModifyDate__c.toStartOfMonth().addMonths(1);

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from FBR_Inquiry__c where ModifyDate__c >= :startDate AND ModifyDate__c < :endDate and PayoffObject__c=:'○' and Status__c IN('対応中' ,'対応完了')];
//LIST<AggregateResult> calmonth=[Select CALENDAR_MONTH(WorkDate__c), count(ImportCount__c) icount from WorkResultsMonth__c where Account_Name__c=:acname GROUP BY CALENDAR_MONTH(WorkDate__c)];
LIST<AggregateResult> calmonth=[Select count(ImportCount__c) icount from WorkResultsMonth__c where WorkDate__c >= :startDate and WorkDate__c < :endDate ];

List<KPIAccident__c> acc= [SELECT MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c ];
if(!acc.isEmpty() )
{

KPIAccident__c accupdate = acc[0];
Integer totalcountmonth=Integer.Valueof(countmonth[0].get('coun'));

accupdate.MonthlyGeneratedCount__c=totalcountmonth;

Integer totalmonthwork= Integer.Valueof(calmonth[0].get('icount'));
accupdate.MonthlyPPM__c=(totalmonthwork/totalcountmonth*1000000);
update accupdate;
}else
{
KPIAccident__c kpi = new KPIAccident__c();
List<KPIAccident__c> ToUpdate = new List<KPIAccident__c>();
// kpi.Date__c=FBR.ModifyDate__c;
//kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;
// kpi.itemname__c= FBR.CommodityName__c;

Integer totalcountmonths=Integer.Valueof(countmonth[0].get('coun'));
kpi.MonthlyGeneratedCount__c=totalcountmonths;
Integer totalmonthworks= Integer.Valueof(calmonth[0].get('icount'));

kpi.MonthlyPPM__c=(totalmonthworks/totalcountmonths*1000000);
ToUpdate.add(kpi);
insert ToUpdate;

}
}
} }

 

 

test case of trigger monthly

 

 

mytest case

 

 

@isTest(SeeAllData=true)
public class FBR_InquiryMonthlyTest
{


public static testMethod void testAMethod1(){
//FBR_ApexScheduleMonthClass f1=new FBR_ApexScheduleMonthClass ();
try
{
Test.startTest();

FBR_ApexScheduleMonthClass.ValAdd();

 

WorkResultsMonth__c f2=new WorkResultsMonth__c ();
f2.name='Test';
//2.ImportCount=15;

f2.ImportCount__c=100;
insert f2;

LIST<FBR_Inquiry__c> cc=new List<FBR_Inquiry__c>();
Date startDate=date.parse('9/09/2012');
Date endDate=date.parse('19/09/2012');

FBR_Inquiry__c m1=new FBR_Inquiry__c();
m1.CommodityName__c='rakuten123';
m1.ModifyDate__c=date.parse('07/09/2012');
m1.KPIInquiryContent__c='one';
cc.add(m1);
insert cc;
List<KPIAccident__c > ss=new List<KPIAccident__c >();
integer dTotalForAll = 12;
integer TotalCounts=251;


KPIAccident__c m2= new KPIAccident__c();
m2.Name='rakuten123' ;

Integer totalcountmonth=dTotalForAll;
m2.MonthlyGeneratedCount__c=totalcountmonth;
Integer totalmonthwork=TotalCounts;
m2.MonthlyPPM__c=(totalmonthwork/totalcountmonth*1000000);

insert ss;


KPIAccident__c kpi = new KPIAccident__c();

// kpi.Date__c=FBR.ModifyDate__c;
//kpi.Account__c=FBR.KPIInquiryContent__r.Account__c;
// kpi.itemname__c= FBR.CommodityName__c;

Integer totalcountmonths=dTotalForAll;
kpi.MonthlyGeneratedCount__c=m2.MonthlyGeneratedCount__c;
Integer totalmonthworks= TotalCounts;

kpi.MonthlyPPM__c=m2.MonthlyPPM__c;

insert kpi;

}
catch(Exception e){}
Test.stopTest();
}


}

 

The above Red mark is not Covering the my Test case.Now i covered test 57%. can any one help me the else condition of the test case.

 

cheers

Pradeep kumar.p

 

SFD SalesforceSFD Salesforce

Hi ,

 

 

my code is above there. but the red mark is not coverage in Testing.

My Test case.

 

 

@isTest(SeeAllData=true)
class InquiryMonthlyTest {
static testMethod void Testcase() {

try
{
Test.startTest();


account a = new account();
a.name='pradeep';
insert a;

// Date startDate=date.parse('19/09/2012');
// Date endDate=date.parse('22/09/2012');
Inquiry__c fi=new Inquiry__c();


fi.CommodityName__c='pradeep';
fi.ModifyDate__c=date.parse('03/09/2012');
fi.Status__c ='good';

insert fi;



WorkResultsMonth__c m1=new WorkResultsMonth__c();
// m1.WorkDate__c =f1.ModifyDate__c;
// m1.Account_Name__c=a.id;
m1.ImportCount__c=Integer.valueOf('10');
insert m1;

Integer totalDetails=256;
Integer dTotal=45263;
FBR_InquiryMonthly1.ValAdd();
List<KPIAccident__c> m4;

m4=[SELECT MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c ];
/* try
{


if(m4.isEmpty())
{
KPIAccident__c accupdate = m4[0];
accupdate.MonthlyGeneratedCount__c=totalDetails;
accupdate.MonthlyPPM__c=dTotal;

update accupdate;
}
else
{
KPIAccident__c m3 = new KPIAccident__c();
List<KPIAccident__c> fas= new List<KPIAccident__c>();



Integer totalcountmonths=totalDetails;

m3.MonthlyGeneratedCount__c=totalcountmonths;

Integer totalmonthworks= dTotal;
m3.MonthlyPPM__c=(totalmonthworks/totalcountmonths*1000000);
fas.add(m3);
insert fas;

}
// update m4;



} */

/* if(m4.isEmpty())
{
KPIAccident__c kp=m4.get(0);
kp.MonthlyGeneratedCount__c=totalDetails;
kp.MonthlyPPM__c=dTotal;

update kp;
}
else
{

// KPIAccident__c n1 = m4.get(0);
// KPIAccident__c m5=m4.get(0);

KPIAccident__c kpi = new KPIAccident__c(MonthlyGeneratedCount__c= totalDetails,MonthlyPPM__c=dTotal);
m4.add(kpi);
insert m4;

}
}*/
KPIAccident__c kc1=new KPIAccident__c(name='rakuten',MonthlyGeneratedCount__c=totalDetails, MonthlyPPM__c=dTotal);
insert kc1;
if(m4.isEmpty())
{

KPIAccident__c kp=m4.get(0);
kp.MonthlyGeneratedCount__c=totalDetails;
kp.MonthlyPPM__c=dTotal;


update kp;
}


else
{
KPIAccident__c kp1=new KPIAccident__c();
List<KPIAccident__c> ss=[SELECT MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c ];
kp1.MonthlyGeneratedCount__c=totalDetails;
kp1.MonthlyPPM__c=dTotal;
//kp1.id=kc1.id;
m4.add(kp1);
insert ss;
}
}
catch(Exception e){}
}
}

 

This is  my  test case code is coverage in 60% . any body help me my test code covered in 75% above this trigger

cheer

Pradeep