I'm trying to write a scheduler Apex class to create an Accounting Period every month and am getting an error when compiling
Method does not exist or incorrect signature: void schedule(String, String, AccountingPeriodCreationService) from the type System
AccountingPeriodCreationService.cls
public with sharing class AccountingPeriodCreationService {
public static List <AcctSeed__Accounting_Period__c> accountingPeriod;
public static Date currentDate;
public static Date firstDayOfCurrentMonth;
public static Date lastDayOfCurrentMonth;
public void createdAPLogic(){
accountingPeriod = new List <AcctSeed__Accounting_Period__c>();
currentDate = Date.today();
firstDayOfCurrentMonth = currentDate.toStartofMonth();
lastDayOfCurrentMonth = currentDate.addMonths(1).toStartofMonth().addDays(-1);
List<AcctSeed__Accounting_Period__c> checkAccountingPeriodAlreadyExist = [SELECT Id, AcctSeed__Start_Date__c, AcctSeed__End_Date__c FROM AcctSeed__Accounting_Period__c where AcctSeed__Start_Date__c = :firstDayOfCurrentMonth];
if(checkAccountingPeriodAlreadyExist.isEmpty()){
accountingPeriod.add(
new AcctSeed__Accounting_Period__c(
Name = 'Name',
AcctSeed__Status__c = 'Status',
AcctSeed__Start_Date__c = firstDayOfCurrentMonth,
AcctSeed__End_Date__c = lastDayOfCurrentMonth
)
);
}
}
}
CreateAccountingPeriods.cls
global with sharing class CreateAccountingPeriods implements Schedulable {
/**
* @description Executes the scheduled Apex job.
* @param sc contains the job ID
*/
global void execute(SchedulableContext sc) {
//Non static method cannot be referenced from a static context
AccountingPeriodCreationService apc = new AccountingPeriodCreationService();
String sch = '0 1 0 1 1/1 ? *';
String jobID = system.schedule('Create Accounting Period', sch, apc);
}
}
With the line below marked up
String jobID = system.schedule('Create Accounting Period', sch, apc);
I've spent the past few hours trying to figure out why the error is there and how to fix it?