+ Start a Discussion
virkvirk 

How to write test for following code?

Can someone help me in writing test for the following code? Specially for the bold text.


global class UpdateStatusAcc implements Database.Batchable<sObject> {
 
 LogAccountTasks__c logAccTasks;
 Boolean flag = false;
 //List<Account> toUpdate;
 global String query;
 global UpdateStatusAcc() {
  query = 'SELECT Id, AccountId__c, AccRecordTypeId__c, AccRTDeveloperName__c, Etat_actuel_de_la_relation_geo__c,Etat_futur_de_la_relation_geo__c, Flag__c, Type_de_reseau__c, CreationDate__c FROM LogAccountTasks__c WHERE flag__c=false';
 }
 
 global Database.QueryLocator start(Database.BatchableContext BC) {
  //String query =
  return Database.getQueryLocator(query);
 }
    global void execute(Database.BatchableContext BC, List<LogAccountTasks__c> lstLogAccountTasks) {
     System.debug('Test');
  List<Id> accIds = new List<Id>();
  List<LogAccountTasks__c> lstTasks; //= new <List>logAccountTasks();
  List<Id> lstAccIds;
  //List<Account> TrigNew;
  Map<id, Account> TrigoldMap;
  List<Account> lstmemoryAcc;
  Account tmpAcc;
  if (lstLogAccountTasks == null || !lstLogAccountTasks.isEmpty()) {
          return;
  }
  
  //Add the AccountId to the Ids List
  for(LogAccountTasks__c LogAcc : lstLogAccountTasks) {
   //Prepare oldMap
   System.debug('inside new list');
   lstAccIds.add(LogAcc.AccountId__c);
   //Prepare List for simulate Trignew
   tmpAcc = null;
   tmpAcc.Id = LogAcc.AccountId__c;
   tmpAcc.Etat_relation_GEO__c = LogAcc.Etat_futur_de_la_relation_geo__c;
   tmpAcc.RecordTypeId = LogAcc.AccRecordTypeId__c;
   tmpAcc.R_seau_int_gr__c = LogAcc.Type_de_reseau__c;
   lstmemoryAcc.add(tmpAcc);
  }

  //create Account object List
  //TrigNew = [SELECT Id, Name, RecordTypeID, R_seau_int_gr__c, Etat_relation_GEO__c FROM Account WHERE Id=:lstAccIds];
  //Create a virtual object of Account
//  for(lstLogAccountTasks)
        //TrigoldMap = new Map<Id, Account>([SELECT Id FROM Account], [SELECT Etat_relation_GEO__c FROM Account]);
        for (Account acc : [select Id, Etat_relation_GEO__c from Account  WHERE Id=:lstAccIds]) {
         System.debug('inside old map');
            TrigoldMap.put(acc.Id, acc);
        }
  UpdateStatus.hierarchyAccountDeploiment(lstmemoryAcc, TrigoldMap);
        UpdateStatus.hierarchyAccountTerminer(lstmemoryAcc, TrigoldMap);
        UpdateStatus.terminerFilByAccount(lstmemoryAcc);
/*  if (logAccountTasks != null && logAccountTasks.size() > 0) {
   for (Account a : logAccountTasks)
        a.Etat_relation_GEO__c = 'Déploiement';
  }
*/
//     update logAccountTasks;
//     flag=true;
 }
 
 global void finish(Database.BatchableContext BC) {
  //if(flag == true && logAccountTasks != null && logAccountTasks.size() > 0)
  // delete logAccountTasks;
  //System.debug('hello');
 }
 
}

thanks in advance.