• Arpita Kaushik 5
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I have the following Batch Job and corresponding test class
Batch Job:
global class WBStrategyBatch implements Database.Batchable<sObject>{

    public String query;
    public static final String QUERY_STRING = 'Select Id, Name, Market_Value_Total__c, (select Id, Name, Market_Value_for_Strategy_Total__c from WB_Accounts__r where Account_Status__c=\'Active\') from WB_Strategy__c where Id IN (Select Strategy__c from WB_Account__c)';
    
    global database.querylocator start(Database.BatchableContext BC)
  {

      return Database.getQueryLocator(query);
  }
  
  global void execute(Database.BatchableContext BC, List<sObject> scope)
  {
    decimal totalMarketValue=0;
    
    for (sObject obj: scope){
      totalMarketValue = 0;
      WB_Strategy__c wbStrategy = (WB_Strategy__c)obj;
      for (WB_Account__c wbAcc: wbStrategy.WB_Accounts__r){
        totalMarketValue = totalMarketValue + wbAcc.Market_Value_for_Strategy_Total__c;
      }
      wbStrategy.Market_Value_Total__c = totalMarketValue;
      update wbStrategy;
    }
      
  }
  
    global void finish(Database.BatchableContext BC)
  {
    System.debug('WB Strategy Groups Batch finished.');
  }
  
}

Test Class:
@isTest
private class WBStrategyBatchTest {
    public static testMethod void testWBStrategy(){
   
    String query = 'Select Id, Name, Market_Value_Total__c, (select Id, Name, Market_Value_for_Strategy_Total__c from WB_Accounts__r where Account_Status__c=\'Active\') from WB_Strategy__c where Id IN (Select Strategy__c from WB_Account__c) LIMIT 2';
   
     WB_Strategy__c[] wbStrgy = new List<WB_Strategy__c>();
    
           WB_Strategy__c wb1 = new WB_Strategy__c(Name='WBStrategy', Market_Value_Total__c=100);  
              
           wbStrgy.add(wb1);
    
     insert wbStrgy;
    
     Test.startTest();
     WBStrategyBatch wb = new WBStrategyBatch();
      Database.executeBatch(wb);
    
     Test.stopTest();
  } 
                     
}
While running the test class I am receiving the following error
System.NullPointerException: Argument 1 cannot be null
Please help
 
I have the following Batch job :

global class AdvisorGroupsBatch implements Database.Batchable<sObject>{
    
    public String query;
    
    global database.querylocator start(Database.BatchableContext BC)
  {
      String query = 'Select Id, Name, YTD_Gross_Adv_Group__c, SV_Assets_for_Team__c, (select Id, Name, YTD_Gross_Sales__c, Assets_with_WB__c from Contacts__r) from Advisor_group__c';
      return Database.getQueryLocator(query);
  }
   global void execute(Database.BatchableContext BC, List<sObject> scope)
  {
      decimal total_YTD;
      decimal total_SV;
      for (sObject obj: scope){
          total_YTD = 0;
          total_SV = 0;
          Advisor_group__c advgrp = (Advisor_group__c)obj;
          for (Contact c: advgrp.Contacts__r){
              total_YTD = total_YTD + c.YTD_Gross_Sales__c;
              total_SV = total_SV + c.Assets_with_WB__c;
          }
          advgrp.YTD_Gross_Adv_Group__c = total_YTD;
          advgrp.SV_Assets_for_Team__c = total_SV;
          update advgrp;
        
      }
  } 
  
  global void finish(Database.BatchableContext BC)
  {
    System.debug('Advisor Groups Batch finished.');
  }
    
}


I am trying to write a test class, following is the test class :
@isTest
private class AdvisorGroupsBatchTest {
    public static testMethod void test(){
       
       String query = 'Select Id, Name, YTD_Gross_Adv_Group__c, SV_Assets_for_Team__c, (select Id, Name, YTD_Gross_Sales__c, Assets_with_WB__c from Contacts__r) from Advisor_group__c LIMIT 2';
    
     Advisor_Group__c[] adv = new List<Advisor_Group__c>();
     
           Advisor_Group__c a1 = new Advisor_Group__c(
               Name='Adv Group',
               Id='000',
               YTD_Gross_Adv_Group__c=100,
               SV_Assets_for_Team__c=200);
 
           adv.add(a1);
     
     insert adv;
     
     Test.startTest();
     AdvisorGroupsBatch a = new AdvisorGroupsBatch(query);
      Database.executeBatch(a);
     //ID batchprocessid = Database.executeBatch(a);
     Test.stopTest();
  } 
                      
}

I am unable to reach a code coverage of 75%. it is not increasing more than 24%. Please suggest

 
I have the following Batch job :

global class AdvisorGroupsBatch implements Database.Batchable<sObject>{
    
    public String query;
    
    global database.querylocator start(Database.BatchableContext BC)
  {
      String query = 'Select Id, Name, YTD_Gross_Adv_Group__c, SV_Assets_for_Team__c, (select Id, Name, YTD_Gross_Sales__c, Assets_with_WB__c from Contacts__r) from Advisor_group__c';
      return Database.getQueryLocator(query);
  }
   global void execute(Database.BatchableContext BC, List<sObject> scope)
  {
      decimal total_YTD;
      decimal total_SV;
      for (sObject obj: scope){
          total_YTD = 0;
          total_SV = 0;
          Advisor_group__c advgrp = (Advisor_group__c)obj;
          for (Contact c: advgrp.Contacts__r){
              total_YTD = total_YTD + c.YTD_Gross_Sales__c;
              total_SV = total_SV + c.Assets_with_WB__c;
          }
          advgrp.YTD_Gross_Adv_Group__c = total_YTD;
          advgrp.SV_Assets_for_Team__c = total_SV;
          update advgrp;
        
      }
  } 
  
  global void finish(Database.BatchableContext BC)
  {
    System.debug('Advisor Groups Batch finished.');
  }
    
}


I am trying to write a test class, following is the test class :
@isTest
private class AdvisorGroupsBatchTest {
    public static testMethod void test(){
       
       String query = 'Select Id, Name, YTD_Gross_Adv_Group__c, SV_Assets_for_Team__c, (select Id, Name, YTD_Gross_Sales__c, Assets_with_WB__c from Contacts__r) from Advisor_group__c LIMIT 2';
    
     Advisor_Group__c[] adv = new List<Advisor_Group__c>();
     
           Advisor_Group__c a1 = new Advisor_Group__c(
               Name='Adv Group',
               Id='000',
               YTD_Gross_Adv_Group__c=100,
               SV_Assets_for_Team__c=200);
 
           adv.add(a1);
     
     insert adv;
     
     Test.startTest();
     AdvisorGroupsBatch a = new AdvisorGroupsBatch(query);
      Database.executeBatch(a);
     //ID batchprocessid = Database.executeBatch(a);
     Test.stopTest();
  } 
                      
}

I am unable to reach a code coverage of 75%. it is not increasing more than 24%. Please suggest