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 

please help me test case error of trigger class

Hi All,

 

can any body the test case error of  trigger .

This is my Test case of trigger:

 

 

global class InquiryMonthly{

public static void ValAdd()//Set<Id> InquiryId
{

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

LIST<AggregateResult> countmonth=[SELECT count(KPIInquiryContent__c) coun from Inquiry__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 Date__c,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__cg1.ModifyDate__c;
// kpi.Account__c=g1.KPIInquiryContent__r.Account__c;
kpi.itemname__c= g1.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;

}
}
}
static testMethod void testAMethod1()
{
Test.startTest();
Account a2 = new Account();
a2.name='rakuten12';
insert a2;
Inquiry__c f1=new Inquiry__c(CommodityName__c='pradeep',ModifyDate__c=date.parse('03/09/2012'),Status__c ='good');
insert f1;
List<KPIAccident__c> ac2=[SELECT Date__c,MonthlyGeneratedCount__c,MonthlyPPM__c from KPIAccident__c];

if(ac2.isEmpty())
{

KPIAccident__c m5=ac2[0];
m5.MonthlyGeneratedCount__c= 129;
m5.MonthlyPPM__c=2563;
//m5.Date__c=f1.ModifyDate__c;
insert m5;
}
else
{
List<KPIAccident__c> listEt = new List<KPIAccident__c>();
KPIAccident__c d1=new KPIAccident__c ();
d1.MonthlyGeneratedCount__c=145;
d1.MonthlyPPM__c=2569;
listEt.add(d1);
try
{
insert listEt;
}
catch(Exception e){}
Test.stopTest();

}
}
}

 

Now  i work both trigger and test case in build the trigger class. But the coverage 65% ,it becomes an error is

 

 

BR_InquiryMonthly.testAMethod1209.0System.DmlException:挿入が失敗しました。行0の最初の例外。最初のエラー:CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY、FBR_AddValue_to_Accident:によって引き起こさAfterInsertの実行:System.ListException:境界の外にリストのインデックス:0 Class.FBR_InquiryMonthly.ValAdd:行38、列1 Trigger.FBR_AddValue_to_Accident:行5、列1 :[]Class.FBR_InquiryMonthly.testAMethod1:行54、列1

 

 

pls  help me my trigger test case  error. and the   should be  covered 75% the above code.

 

cheers

Pradeep