0

I need to improve my code coverage please can any one help me out

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;
}

My test class:

@isTest
private class Rfleet_UpdateforecastAllCountry_Test {
static testmethod void Rfleet_UpdateforecastAllCountry_TestMethod(){

Country_DCVF_Volume__c ContryDCVF = new Country_DCVF_Volume__c(
CurrencyIsoCode='India', 
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;      
    IKAM_Data__c ikam= new IKAM_Data__c(
    Annual_global_deliveries_commitment__c=09.0,
    Annual_deliveries_target__c=72,
    Account__c='Bosch',
    IKAM_Year__c=2015
);
insert ikam;

}
}
  • ContryDCVF is going to be null. can you verify you are passing all the required values. – Himanshu Nov 12 '15 at 10:12
  • may be some required fields are missing. Please post the full error message – highfive Nov 12 '15 at 10:16
  • thanks for your immediate response Himanshu and highfive .it's my error msg: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Currency ISO Code: invalid currency code: India: [CurrencyIsoCode] – Jansi Nov 12 '15 at 10:21
1

CurrencyIsoCode must be a three-letter code that identifies a country's currency, like USD stands for United States Dollars, or JPY for Japanese Yen.

Indian Rupee is INR.

  • I made changes getting same error – Jansi Nov 12 '15 at 11:08
  • What are those Parent Account and Ikam Data? Are you sure those references exist? Remember, in test classes, you cannot reference the records that are saved in your organization. If you need those two references, you will need to insert test objects for those too. – Renato Oliveira Nov 12 '15 at 12:49
  • I covered my test class 86% this part is not covered: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); } Please can you help me out – Jansi Nov 13 '15 at 4:11
  • Well, this is called when the context is "isDelete" so you should try deleting the Country_DCVF_Volume__c you created before. – Renato Oliveira Nov 13 '15 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.