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
chaithaly gowdachaithaly gowda 

how to check assert equals for scheduled class

Hi

I have a scheduled class for which I am writing test class.
So this scheduled class is inserting few records ,and how would I check in my test class that record is inserted or not.

I tried with below code.. but the execute method of scheduled class is executing after all statements in test classs, due to which I am not able to do assert equals for the records created.


@isTest
    static void test_SA_MG(){
  
        User u = [select Id from User where id =: UserInfo.getUserId() limit 1];
        
            system.runAs(u){
            Test.startTest(); 
           ReminderController Notification= new ReminderController('30 Days Reminder');
           Datetime sysTime = System.now().addSeconds(10);      
            String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
             System.schedule('Reminder', chronExpression,Notification);

            list<xyz__c> sc=[select id from xyz__c];
system.assertequals(1,sc.size());
            Test.stopTest();
        }

when I set the debug log for the above code.. I see the records are inserted for xyz__c object in scheduled class.. but list sc has 0 records.

Please let me know what can be done to solve this.
Thanks in advance
AnudeepAnudeep (Salesforce Developers) 
Can you move your query to an async call (@future) and see if it returns results?