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
Lori BuchowiczLori Buchowicz 

System.AsyncException: Based on configured schedule, the given trigger 'SCHEDULED_APEX_JOB_TYPE.000000000000000' will never fire.

Schedule returning error message - assistance needed please:
*/
@isTest
public class NightlyDepositBatchTest {
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
@testSetup
static void setup() {
List donations = new List();
for (Integer i=0;i donList = [SELECT Id, Donation_Use__c, Tributee__c, Gift_Type__c, Amount__c, GL_Code__c FROM Donations__c];
for(Donations__c donation: donList){
Test.setCreatedDate(donation.id, Datetime.newInstance(date.today(), Time.newInstance(0,0,0,0)).addDays(-1));
}
update donList;

}
@isTest static void test() {
Test.startTest();
NightlyDepositBatch uca = new NightlyDepositBatch(Date.today());
Id batchId = Database.executeBatch(uca);
Test.stopTest();
// after the testing stops, assert records were created properly
List depositLines = [SELECT Id,SUM(Amount__c) FROM QB_Deposit_Line__c GROUP BY Id LIMIT 1];
System.assertEquals(100, (Decimal)depositLines[0].get('expr0'));
}
@isTest static void test2() {
Test.startTest();
String jobId = System.schedule('ScheduledApexTest',
CRON_EXP,
new NightlyDepositSchedule());
Test.stopTest();
}
}
Unit test now returning error when deploying new test cases for other development being done and this test case not firing the scheduled test job. I have been searching for how to fix the test case and am not finding how to best resolve in the sandbox to update this and get any coverage listed for the Nightly Batch Schedule job in production.

With this above issue not able to get code coverage on this job -
global class NightlyDepositSchedule implements Schedulable{

global void execute(SchedulableContext sc) {
NightlyDepositBatch n1 = new NightlyDepositBatch(Date.today());
ID batchprocessid = Database.executeBatch(n1,Test.isRunningTest() ? 3 : 1);
}
}
Best Answer chosen by Lori Buchowicz
Abdul KhatriAbdul Khatri
Hi Lori,

It is not firing because the CRON_EXP = '0 0 0 15 3 ? 2022' is in the past. You need to put in the future so it can run for a long time.

Here is the screen shot with the highlighted part I fixed. The shared code has too many missing curly brackets and some code issues, which I have fixed and shared below.
User-added image
 
Here is fixed code.
@isTest
public class NightlyDepositBatchTest {
    
    public static String CRON_EXP = '0 0 0 15 3 ? 2023';
    
    @testSetup
    static void setup() 
    {
        List<Donations__c> donations = new List<Donations__c>();
        for (List<Donations__c> donList : [SELECT Id, Donation_Use__c, Tributee__c, Gift_Type__c, Amount__c, GL_Code__c FROM Donations__c])
        {
             for(Donations__c donation: donList)
             {
                 Test.setCreatedDate(donation.id, Datetime.newInstance(date.today(), Time.newInstance(0,0,0,0)).addDays(-1));
             }
             update donList;
             
        }
    }
        
    @isTest
    public static void test() 
    {
        Test.startTest();
        NightlyDepositBatch uca = new NightlyDepositBatch(Date.today());
        Id batchId = Database.executeBatch(uca);
        Test.stopTest();
        // after the testing stops, assert records were created properly
        AggregateResult[] depositLines = [SELECT Id,SUM(Amount__c) FROM QB_Deposit_Line__c GROUP BY Id LIMIT 1];
        System.assertEquals(100, (Decimal)depositLines[0].get('expr0'));
    }
    
    @isTest 
    public static void test2() {
        Test.startTest();
        String jobId = System.schedule('ScheduledApexTest',
                                       CRON_EXP,
                                       new NightlyDepositSchedule());
        Test.stopTest();
    }
}

I hope this help.

Please don't forget to mark it a best answer.

All Answers

Abdul KhatriAbdul Khatri
Hi Lori,

It is not firing because the CRON_EXP = '0 0 0 15 3 ? 2022' is in the past. You need to put in the future so it can run for a long time.

Here is the screen shot with the highlighted part I fixed. The shared code has too many missing curly brackets and some code issues, which I have fixed and shared below.
User-added image
 
Here is fixed code.
@isTest
public class NightlyDepositBatchTest {
    
    public static String CRON_EXP = '0 0 0 15 3 ? 2023';
    
    @testSetup
    static void setup() 
    {
        List<Donations__c> donations = new List<Donations__c>();
        for (List<Donations__c> donList : [SELECT Id, Donation_Use__c, Tributee__c, Gift_Type__c, Amount__c, GL_Code__c FROM Donations__c])
        {
             for(Donations__c donation: donList)
             {
                 Test.setCreatedDate(donation.id, Datetime.newInstance(date.today(), Time.newInstance(0,0,0,0)).addDays(-1));
             }
             update donList;
             
        }
    }
        
    @isTest
    public static void test() 
    {
        Test.startTest();
        NightlyDepositBatch uca = new NightlyDepositBatch(Date.today());
        Id batchId = Database.executeBatch(uca);
        Test.stopTest();
        // after the testing stops, assert records were created properly
        AggregateResult[] depositLines = [SELECT Id,SUM(Amount__c) FROM QB_Deposit_Line__c GROUP BY Id LIMIT 1];
        System.assertEquals(100, (Decimal)depositLines[0].get('expr0'));
    }
    
    @isTest 
    public static void test2() {
        Test.startTest();
        String jobId = System.schedule('ScheduledApexTest',
                                       CRON_EXP,
                                       new NightlyDepositSchedule());
        Test.stopTest();
    }
}

I hope this help.

Please don't forget to mark it a best answer.
This was selected as the best answer
Lori BuchowiczLori Buchowicz
Thank you!