Guest User

Untitled

a guest
Dec 12th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public with sharing class AccountingPeriodCreationService {
  2.  
  3. public static List <AcctSeed__Accounting_Period__c> accountingPeriod;
  4. public static Date currentDate;
  5. public static Date firstDayOfCurrentMonth;
  6. public static Date lastDayOfCurrentMonth;
  7.  
  8. public void createdAPLogic(){
  9. accountingPeriod = new List <AcctSeed__Accounting_Period__c>();
  10. currentDate = Date.today();
  11. firstDayOfCurrentMonth = currentDate.toStartofMonth();
  12. lastDayOfCurrentMonth = currentDate.addMonths(1).toStartofMonth().addDays(-1);
  13.  
  14.  
  15. 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];
  16.  
  17. if(checkAccountingPeriodAlreadyExist.isEmpty()){
  18. accountingPeriod.add(
  19. new AcctSeed__Accounting_Period__c(
  20. Name = 'Name',
  21. AcctSeed__Status__c = 'Status',
  22. AcctSeed__Start_Date__c = firstDayOfCurrentMonth,
  23. AcctSeed__End_Date__c = lastDayOfCurrentMonth
  24. )
  25. );
  26. }
  27. }
  28. }
  29.  
  30. global with sharing class CreateAccountingPeriods implements Schedulable {
  31. /**
  32. * @description Executes the scheduled Apex job.
  33. * @param sc contains the job ID
  34. */
  35.  
  36. global void execute(SchedulableContext sc) {
  37. //Non static method cannot be referenced from a static context
  38. AccountingPeriodCreationService apc = new AccountingPeriodCreationService();
  39. String sch = '0 1 0 1 1/1 ? *';
  40. String jobID = system.schedule('Create Accounting Period', sch, apc);
  41. }
  42.  
  43.  
  44. }
Add Comment
Please, Sign In to add comment