function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ponneri navadeepponneri navadeep 

Hi how to cover the below code in test class




User-added image






  try{
            String query = '';
            DateTime lastRunDateTime = AccountTeamBatchHandler.getLastRunDateTime('Core_IPS_AccountTeamUpdate_Scheduler');
            if(lastRunDateTime!=null)
                batchProcessing.Core_Last_Run_Date__c = lastRunDateTime;
            if(Test.isRunningTest()){
                query = 'select id from Account where id in(select accountid from accountshare where lastmodifieddate >= TODAY)';
            }else if(lastRunDateTime!=null){
                batchProcessing.Core_Start_Date_Time__c = system.Now();
                query = 'select id from Account where id in(select accountid from accountshare where lastmodifieddate >= :lastRunDateTime and rowcause=\'Team\')';
            }else{
                throw new BatchException('Core_IPS_AccountTeamUpdate_Scheduler not started as Lasr Run Batch Time is not specified');
            }
            batchProcessing.Batch_Header__C = header.id;
            batchProcessing.Core_Salesforce_Job_Id__c = BC.getJobId();
            batchProcessing.Core_Batch_Query__c = query;
            batchProcessing.Core_Email_Distribution_List__c=header.Email_Distribution_List__c;
            batchProcessing.Core_Object_Name__c = 'Account';
            insert batchProcessing;
Amit Chaudhary 8Amit Chaudhary 8
Update your code like below and try same test class
try{
            String query = '';
            DateTime lastRunDateTime = AccountTeamBatchHandler.getLastRunDateTime('Core_IPS_AccountTeamUpdate_Scheduler');
            if(lastRunDateTime!=null)
			{
                batchProcessing.Core_Last_Run_Date__c = lastRunDateTime;
                batchProcessing.Core_Start_Date_Time__c = system.Now();
                query = 'select id from Account where id in(select accountid from accountshare where lastmodifieddate >= :lastRunDateTime and rowcause=\'Team\')';
			}		
			
            if(Test.isRunningTest()){
                query = 'select id from Account where id in(select accountid from accountshare where lastmodifieddate >= TODAY)';
            }
            else
			{
                throw new BatchException('Core_IPS_AccountTeamUpdate_Scheduler not started as Lasr Run Batch Time is not specified');
            }
            batchProcessing.Batch_Header__C = header.id;
            batchProcessing.Core_Salesforce_Job_Id__c = BC.getJobId();
            batchProcessing.Core_Batch_Query__c = query;
            batchProcessing.Core_Email_Distribution_List__c=header.Email_Distribution_List__c;
            batchProcessing.Core_Object_Name__c = 'Account';
            insert batchProcessing;

Let us know if this will help you in code coverage