Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- )
- );
- }
- }
- }
- 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);
- }
- }
Add Comment
Please, Sign In to add comment