0

I have written test classes for trigger it's covered 86%. I need to increase code coverage for 100% below I Bold line is not covered. Please can any one help me out what do I need to change.

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

Test class:

@isTest
public class Rfleet_UpdateforecastAllCountry_Test{

    static testMethod void UpdateforecastAllCountry(){

     IKAM_Data__c ikam= new IKAM_Data__c();
        ikam.Annual_deliveries_target__c=85;
        ikam.Annual_global_deliveries_commitment__c=90;
        ikam.Account__c='001m000000NPHo3'; // insert some account and use that id here 001m000000NPFrU
        ikam.IKAM_Year__c=2015;
        test.startTest();
        insert ikam;

      country_dcvf_volume__c con = new country_dcvf_volume__c();
        con.Country__c='Algeria';
        con.Region__c='France';
        con.Insertion_date__c=system.Today();
        con.KAM__c='Prabu';
        con.Country_forecast__c=3;
        con.Delivered_volume__c=1;
        con.Parent_Account__c='001m000000NPHo3';  // insert some account and use that id here  001m000000NFrdp
        con.IKAM_Data__c=ikam.id;
        insert con;
        test.stopTest();
    }
}

1 Answer 1

2

Try this..

@isTest
public class Rfleet_UpdateforecastAllCountry_Test{

    static testMethod void UpdateforecastAllCountry(){

     IKAM_Data__c ikam= new IKAM_Data__c();
        ikam.Annual_deliveries_target__c=85;
        ikam.Annual_global_deliveries_commitment__c=90;
        ikam.Account__c='001m000000NPHo3'; // insert some account and use that id here 001m000000NPFrU
        ikam.IKAM_Year__c=2015;
        test.startTest();
        insert ikam;

      country_dcvf_volume__c con = new country_dcvf_volume__c();
        con.Country__c='Algeria';
        con.Region__c='France';
        con.Insertion_date__c=system.Today();
        con.KAM__c='Prabu';
        con.Country_forecast__c=3;
        con.Delivered_volume__c=1;
        con.Parent_Account__c='001m000000NPHo3';  // insert some account and use that id here  001m000000NFrdp
        con.IKAM_Data__c=ikam.id;
        insert con;
        delete con;
        test.stopTest();
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .