0

Controller:

global class QuarterlyRollupBatch implements Database.batchable<Opportunity> {
    Public Date lastDateOfThisQuarter,fiscalYearStartDate,firstDateOfNextQuarter;
    Public Integer quarter;

    global Iterable<Opportunity>  start(Database.BatchableContext info) { 

        Integer FiscalYearStartMonth = 1;// [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;

        Date todaydate = system.today();
        fiscalYearStartDate = date.newinstance(system.today().year(), FiscalYearStartMonth, 1);
        quarter = ((system.today().month() - FiscalYearStartMonth) / 3) + 1;

        Integer addMonths = quarter * 3;

        lastDateOfThisQuarter = fiscalYearStartDate;
        //Date closeDate = [Select EndDate From Period Where type = 'Quarter' and StartDate = THIS_FISCAL_QUARTER].EndDate;

        // this is the last date of the current quarter
        lastDateOfThisQuarter = lastDateOfThisQuarter.addMonths(addMonths).addDays(-1);
        firstDateOfNextQuarter=lastDateOfThisQuarter.addDays(1);
        System.debug('@@@ '+firstDateOfNextQuarter);

        List<Opportunity> oppList=[select id,name,Est_Syndication_Completion_Date__c,income_Timing__c,Owner.Name from Opportunity where  Est_Syndication_Completion_Date__c <: firstDateOfNextQuarter and Est_Syndication_Completion_Date__c >=: todaydate and income_Timing__c='Future Opportunity'];

        system.debug('Opplist'+oppList); 
        return oppList;      
    }

    global void execute(Database.BatchableContext info, List<Opportunity> oppList) {
        if (oppList.size() > 0) {
            for( Opportunity o:oppList) {            
                o.income_Timing__c = 'Current Opportunity';
            }
            update oppList;
        }    
    }

    global void finish(Database.BatchableContext info){ }
}


global class QuarterlyRollupBatchsch implements Schedulable {
    global void execute(SchedulableContext sc) {

        Integer FiscalYearStartMonth = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;
        Integer Currentmonth = Date.Today().Month(); 

        QuarterlyRollupBatch createquarterupdate= new QuarterlyRollupBatch();
        if(currentmonth==FiscalYearStartMonth || math.mod(Currentmonth,3)==1) {
            database.executebatch(createquarterupdate,100);    
        }
    }
}
3
  • Are you getting any errors. Was it working at one time and now not working. Need some more details beyond just the code itself to try to help. Commented Feb 25, 2014 at 12:14
  • I am not getting errors.It is working in dev sandbox. Here i didn't schedule any jobs in dev.Just through developer console i tested it.It is working.
    – user5257
    Commented Feb 25, 2014 at 14:06
  • Well then the title of the question is very misleading. It ends with 'is not working'. I don't understand what you are asking for then. Commented Feb 25, 2014 at 14:14

0

You must log in to answer this question.

Browse other questions tagged .