global class ConsumableTargetManageBatch7 implements Database.Batchable { public Date currentMonth; public Date endDate; public Date startDate; public String queryStr; public String year; public Boolean isIncrementOnly; //是否只跑增量 public String OCSMYear; global ConsumableTargetManageBatch7(Date startDate,Date endDate) { this.startDate=startDate; this.endDate=endDate; Integer year = startDate.year(); Integer FYear = year; if(startDate>=Date.newInstance(year, 4, 1)){ FYear = FYear+1; } String OCSMYear= 'FY'+FYear; this.OCSMYear=OCSMYear; queryStr = 'SELECT SpecialistVisitsNum1__c,SpecialistVisitsNum2__c,SpecialistVisitsNum3__c,' +' SpecialistVisitsNum4__c,SpecialistVisitsNum5__c,SpecialistVisitsNum6__c,SpecialistVisitsNum7__c,SpecialistVisitsNum8__c,' +'SpecialistVisitsNum9__c,SpecialistVisitsNum10__c,SpecialistVisitsNum11__c,SpecialistVisitsNum12__c FROM ConsumableTargetManage__c WHERE OCM_Year__c = :OCSMYear'; } global Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator(queryStr); } global void execute(Database.BatchableContext BC, list scope) { for(ConsumableTargetManage__c ctm:scope){ if(ctm.SpecialistVisitsNum1__c==null){ ctm.SpecialistVisitsNum1__c=0; } if(ctm.SpecialistVisitsNum2__c==null){ ctm.SpecialistVisitsNum2__c=0; } if(ctm.SpecialistVisitsNum3__c==null){ ctm.SpecialistVisitsNum3__c=0; } if(ctm.SpecialistVisitsNum4__c==null){ ctm.SpecialistVisitsNum4__c=0; } if(ctm.SpecialistVisitsNum5__c==null){ ctm.SpecialistVisitsNum5__c=0; } if(ctm.SpecialistVisitsNum6__c==null){ ctm.SpecialistVisitsNum6__c=0; } if(ctm.SpecialistVisitsNum7__c==null){ ctm.SpecialistVisitsNum7__c=0; } if(ctm.SpecialistVisitsNum8__c==null){ ctm.SpecialistVisitsNum8__c=0; } if(ctm.SpecialistVisitsNum9__c==null){ ctm.SpecialistVisitsNum9__c=0; } if(ctm.SpecialistVisitsNum10__c==null){ ctm.SpecialistVisitsNum10__c=0; } if(ctm.SpecialistVisitsNum11__c==null){ ctm.SpecialistVisitsNum11__c=0; } if(ctm.SpecialistVisitsNum12__c==null){ ctm.SpecialistVisitsNum12__c=0; } } update scope; } global void finish(Database.BatchableContext BC) { } }