You need to sign in to do that
Don't have an account?
kathir Ravan
test class error System.DmlException: Insert failed. First exception on row 0; first error:
I am new for test class even i tried to write to test classes please find below.Please can any one help me what did i wrong my code i need code coverage.what should do i change my code.
This is trigger:
This is trigger:
trigger Rfleet_UpdateforecastAllCountry on Country_DCVF_Volume__c (after insert,after update,after delete) { string TempYear; Integer TempMonth; Integer FinalVolume=0; Integer FinalForecast=0; set<id>Ikamids=new set<id>(); set<id>Accountids=new set<id>(); if(trigger.isinsert||trigger.isupdate ){ for(Country_DCVF_Volume__c Dcvfcount:trigger.new){ if(Dcvfcount.IKAM_Data__c!=null){ Ikamids.add(Dcvfcount.IKAM_Data__c); Accountids.add(Dcvfcount.Parent_Account__c); } } } if(trigger.isdelete){ for(Country_DCVF_Volume__c Dcvfcount:trigger.old){ if(Dcvfcount.IKAM_Data__c!=null){ Ikamids.add(Dcvfcount.IKAM_Data__c); Accountids.add(Dcvfcount.Parent_Account__c); } } } list<country_dcvf_volume__c>listVol=[select id,insertion_date__c, country__c, Year__c from country_dcvf_volume__c where IKAM_Data__c in:Ikamids and Parent_Account__c in:Accountids ORDER BY insertion_date__c desc limit 1]; for(country_dcvf_volume__c FirstList :listVol){ TempYear=string.Valueof(FirstList.Year__c); TempMonth=integer.valueof(FirstList.insertion_date__c.month()); } list<IKAM_Data__c>finalcount=new list<IKAM_Data__c>(); list<country_dcvf_volume__c> SecondSortedList=[select id,Country_forecast__c ,IKAM_Data__c, Delivered_volume__c from country_dcvf_volume__c where IKAM_Data__c in:Ikamids and Parent_Account__c in:Accountids and Year__c =:TempYear and CALENDAR_month(insertion_date__c)=:TempMonth ]; list<IKAM_Data__c>Ikamupdate=[select id,Countries_delivered_volume__c,Countries_forecast__c from IKAM_Data__c where id in:Ikamids ]; for(country_dcvf_volume__c FinalList :SecondSortedList){ for(IKAM_Data__c updateIkam:Ikamupdate){ FinalVolume +=integer.valueof(FinalList.Delivered_volume__c); FinalForecast +=integer.valueof(FinalList.Country_forecast__c); updateIkam.Countries_delivered_volume__c=FinalVolume; updateIkam.Countries_forecast__c=FinalForecast ; } } update Ikamupdate; }It's test class:
@isTest private class Rfleet_UpdateforecastAllCountry_Test { static testmethod void Rfleet_UpdateforecastAllCountry_TestMethod(){ Country_DCVF_Volume__c ContryDCVF = new Country_DCVF_Volume__c( Country__c='Algeria', Parent_Account__c='001m000000Kg3ys', Region__c='France', Insertion_date__c=system.today(), KAM__c='Ganz Bruno', Delivered_volume__c=1.5, IKAM_Data__c='a3em0000000DCsq' ); insert ContryDCVF; } }
Also i belive it failing at the point in test class it self whn you are trying to insert that ContryDCVF
There must be more of that error DmlException Insert failed., due to multiple reason
may be due to some validation rule it is not getting save or may be you are missing any required field
Please post complite Error message