2

We are going to enable Custom fiscal year feature in our org. And there is batch apex class which calculates the opportunity forcast which is scheduled to run 1st of every month ( Standard Fiscal Year ).

If we enable custom fiscal year and add this template 4-4-5 fiscal year that has 4 quarters and 13 weeks per quarter.

I want to schedule the above batch apex class to run on start date of every custom fiscal month(Custom Fiscal year) e.g., for March 2011,start date would be 02/27/2011 . Can we do this through the standard apex scheduler? If not, How to implement this?

Thanks in advance

3
  • I can think way , can you post the start method of your batch ? Commented Aug 19, 2015 at 6:36
  • Not implement yet. For example I want to select sales orders depend on the fiscal month. The month start date maybe Aug 15, 2015, the month end date maybe Sep 14, 2015. How can I get the month start date and end date? The I can do select in Apex like this select Id, Quantity from Order where OrderDate__c >= :fMonthStartDate and OrderDate__c <= : fMonthEndDate
    – BruceYue
    Commented Aug 20, 2015 at 1:55
  • Do you find solution on scheduling batch job based on org. fiscal calendar?
    – unidha
    Commented Oct 4, 2016 at 4:59

1 Answer 1

1

Hope this helps someone. First, It's not possible with a Cron Expression because Fiscal Years vary unlike Calendar years and Schedulable classes will take Cron Expressions to determine the schedule.

The Fiscal Periods are stored in Period Objects.

global class ScheduledCampaignStageUpdate implements Schedulable {
  
  global void execute(SchedulableContext SC) {
    List<Period> periods = [SELECT StartDate, EndDate, Number FROM Period WHERE FiscalYearSettings.Name >= :currentFiscalYear];
    Date today = Date.today();
    for(Period p: periods) {
      if(today == p.StartDate) {
        // call your Batch Job here
      }
    }
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .