• Mari Dana
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi Folks, I have a use case that I need to display total  amount sum from opportunities object in finsh method... please help me ...
Hi guyz,

I have written a Test class for Batch clas with the help of google. but I could able to cover only 14%. In debug log My Execute method was not covered. Any help?

My Class :
global class batchVATenureUpdate implements Database.Batchable<AggregateResult>
{
    global Iterable<AggregateResult> start(Database.BatchableContext info)
    {
        return new AggregateVAtenureIterable();       
    }
    
    global void execute(Database.BatchableContext info,  List<AggregateResult> accva )
    {
        List<Our_VA__c> ourvalist = new List<Our_VA__c>();
        map<string,Decimal> mapva = new map<string,Decimal>();
        integer i;
        
        for(AggregateResult av : accva)
        {     
            mapva.put(string.valueof(av.get('VA__c')),(Decimal)av.get('daycount'));         
        }
        map<Id,Our_VA__c> ourva = new map<Id,Our_VA__c>();  
        List<Our_VA__c> ourva1 = new List<Our_VA__c>();
        ourva1 = [select id,VA_Tenure_Active_Clients__c,VA_Tenure_Cancellation__c,Account_Number__c,BonusCount__c,Name,ClientCount__c,LoanCount__c,test__c from Our_VA__c];// where id IN:vaids];
       
        for(Our_VA__c a : ourva1)
        {            
            ourva.put(a.id,a);
            string idva = string.valueof(a.id);
            if(mapva.containskey(idva) == true)
            {
                a.VA_Tenure_Active_Clients__c = mapva.get(idva);
                ourvalist.add(a);
            }
        } 
        update ourvalist;              
    }   
    global void finish(Database.BatchableContext BC)
    {
    }
}

Test class :
@isTest

public class TestvaTenureactiveclients1
{

 public static testmethod void batchVATenureUpdate()
    {
         
     our_va__c v1 = new our_va__c();
     v1.name = 'v1';
     insert v1;
     
     Account_VA__c accva = new Account_VA__c();
     accva.Account__c = a1.id;
     accva.VA__c = v1.id;
     accva.Status__c = 'Active';
     accva.Type__c = 'Full Time';
     accva.VA_start_Date__c = Null;
     insert accva;
     
     Test.StartTest();
     list<account_va__c> accvax=new list<account_va__c>();
     accvax.add(accva);
     upsert accvax;
     
     list<our_va__c> ourvax=new list<our_va__c>();
     ourvax.add(v1);
     upsert ourvax;    
     
     batchVATenureUpdate objBatch = new batchVATenureUpdate();
     Database.executeBatch(objBatch);
     Test.StopTest();
    }
}

Thanks,