You need to sign in to do that
Don't have an account?
chaithaly 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
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
Anudeep (Salesforce Developers)
Can you move your query to an async call (@future) and see if it returns results?