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
Thomas Schmidt 11Thomas Schmidt 11 

Test Class for Class that schedules the execution of a flow

Hi, 
i built a quite big flow and missed to build it as a scheduled flow.
As i don´t want to rebuild it i just used a scheduled ApexClass to trigger the flow.

As i am really new to apex i have a hard time figuring out how to make a testingclass for that case. This is my class that invokes the flow:
 
global class AbsenceRenewal  implements Schedulable{
    
    global void execute(SchedulableContext sc){ 
        if(Date.Today().month()==12){
            AbsenceRenewal();
        }  
    }
   
    private void AbsenceRenewal() {   
        Map<String, Object> params = new Map<String, Object>();
        Flow.Interview.Create_Absences_for_next_Year ABflow = new Flow.Interview.Create_Absences_for_next_Year(params);
        ABflow.start();
    }
    
}

and of what i found from the internet i came this far with my testclass:
 
@isTest
private class AbsenceRenewalScheduledTest{
     
    static testmethod void schedulerTest(){
         
        String cronexpression = '0 0 0 15 3 ? *';
        
        
         
        Test.startTest();
        
        AbsenceRenewal.AbsenceRenewal();
        String jobId = System.schedule('AbsenceRenewal',  cronexpression, new AbsenceRenewal());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        System.assertEquals(cronexpression, ct.CronExpression);
        System.assertEquals(0, ct.TimesTriggered);
        
        
        Test.stopTest();
    }
}

that way i get 28% code coverage but actually really only the Schedulable interface is tested. How can i test the flowexecution?

Best regards,
Thomas
ANUTEJANUTEJ (Salesforce Developers) 
Hi Thomas,

>> https://salesforce.stackexchange.com/questions/305028/my-apex-class-is-calling-flow-how-to-wirte-test-class-for-that-apex-class

I was able to find the above link that could help in your use case.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.