• Isha Saxena 18
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I am really trying to cover the forllowing batch with test class please help :

Batch class:

/*
Name: BatchOpportunitySnapshotReportCreation
Copyright © 2019 SAI Global

Purpose:CMPS-2557 On reporting on opportunity records by performing aggregation using multiple criteria
   
VERSION  AUTHOR            DATE             DETAIL                FEATURES/CSR/TTP
    1.0  Isha Saxena     17 July 2019         Inital Creation
*/

global class BatchOpportunitySnapshotReportCreation implements Database.Batchable<SObject>,Database.Stateful
{
     global final Set<Id> ownerList = new Set<Id>();
     global string exceptn= '';
     global string query; 
     global boolean isTestRunning;
      List<User> FYoppOwners = new List<User>();
     global BatchOpportunitySnapshotReportCreation()
     {
         System.debug('Constructor calling@@@@@@');
         FYoppOwners = [SELECT Id,Name,Team__c,Area__c,CurrencyIsoCode FROM User WHERE Id IN (SELECT OwnerId FROM Opportunity WHERE CloseDate = THIS_FISCAL_YEAR)];
         System.debug('Constructor calling@@@@@@'+FYoppOwners);
         if(FYoppOwners.size()>0)
         {
             for(user uid : FYoppOwners)
             {
                 ownerList.add(uid.Id);
             }
         }
     }   
     global database.QueryLocator start(Database.BatchableContext BC)
    {
        System.debug('Opportunity Owner list&&&&&&'+ownerList);
       
        List<Opportunity> oppReport = new List<Opportunity>();
         if(isTestRunning==null)
         {
            isTestRunning = false;
         }  
         
         query = 'SELECT Id,Total_First_Year_Revenue__c ,X1st_Year_Expected_Revenue__c,Probability,ExpectedRevenue,Amount,OwnerId,Owner.CurrencyIsoCode,Days_took_to_Close__c,Owner.Name,Owner.Team__c,Owner.Area__c,StageName' +
                        ' FROM Opportunity' +
                          ' WHERE OwnerId IN : ownerList' +
                          ' AND CloseDate = THIS_FISCAL_YEAR'+
                        ' ORDER BY Owner.Name,Owner.Team__c,Owner.Area__c,StageName';
         System.debug(LoggingLevel.DEBUG, query);
         return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, List<Opportunity> opptysToReport)
    {
        try
        {
            
            System.debug('execute function@@@@@@@@'+opptysToReport);
            if(opptysToReport.size()>0)
            {
                    OpportunitySnapshotHelper.executeSnapshotCreation(opptysToReport,FYoppOwners);
            }
        }
        catch(Exception e)
        {
             exceptn += e.getMessage();  
            System.debug('@@@@@@Exception'+exceptn);
        }
        
    }
    global void finish(Database.BatchableContext BC)
    {
       
        
         System.debug(LoggingLevel.WARN,'Opportunity Snapshot is Complete!');
     }
}


Please help me with the test class
   



 
I am really trying to cover the forllowing batch with test class please help :

Batch class:

/*
Name: BatchOpportunitySnapshotReportCreation
Copyright © 2019 SAI Global

Purpose:CMPS-2557 On reporting on opportunity records by performing aggregation using multiple criteria
   
VERSION  AUTHOR            DATE             DETAIL                FEATURES/CSR/TTP
    1.0  Isha Saxena     17 July 2019         Inital Creation
*/

global class BatchOpportunitySnapshotReportCreation implements Database.Batchable<SObject>,Database.Stateful
{
     global final Set<Id> ownerList = new Set<Id>();
     global string exceptn= '';
     global string query; 
     global boolean isTestRunning;
      List<User> FYoppOwners = new List<User>();
     global BatchOpportunitySnapshotReportCreation()
     {
         System.debug('Constructor calling@@@@@@');
         FYoppOwners = [SELECT Id,Name,Team__c,Area__c,CurrencyIsoCode FROM User WHERE Id IN (SELECT OwnerId FROM Opportunity WHERE CloseDate = THIS_FISCAL_YEAR)];
         System.debug('Constructor calling@@@@@@'+FYoppOwners);
         if(FYoppOwners.size()>0)
         {
             for(user uid : FYoppOwners)
             {
                 ownerList.add(uid.Id);
             }
         }
     }   
     global database.QueryLocator start(Database.BatchableContext BC)
    {
        System.debug('Opportunity Owner list&&&&&&'+ownerList);
       
        List<Opportunity> oppReport = new List<Opportunity>();
         if(isTestRunning==null)
         {
            isTestRunning = false;
         }  
         
         query = 'SELECT Id,Total_First_Year_Revenue__c ,X1st_Year_Expected_Revenue__c,Probability,ExpectedRevenue,Amount,OwnerId,Owner.CurrencyIsoCode,Days_took_to_Close__c,Owner.Name,Owner.Team__c,Owner.Area__c,StageName' +
                        ' FROM Opportunity' +
                          ' WHERE OwnerId IN : ownerList' +
                          ' AND CloseDate = THIS_FISCAL_YEAR'+
                        ' ORDER BY Owner.Name,Owner.Team__c,Owner.Area__c,StageName';
         System.debug(LoggingLevel.DEBUG, query);
         return Database.getQueryLocator(query);
        
    }
    global void execute(Database.BatchableContext BC, List<Opportunity> opptysToReport)
    {
        try
        {
            
            System.debug('execute function@@@@@@@@'+opptysToReport);
            if(opptysToReport.size()>0)
            {
                    OpportunitySnapshotHelper.executeSnapshotCreation(opptysToReport,FYoppOwners);
            }
        }
        catch(Exception e)
        {
             exceptn += e.getMessage();  
            System.debug('@@@@@@Exception'+exceptn);
        }
        
    }
    global void finish(Database.BatchableContext BC)
    {
       
        
         System.debug(LoggingLevel.WARN,'Opportunity Snapshot is Complete!');
     }
}


Please help me with the test class