global class NFM621ControllerBatch implements Database.Batchable < sObject > , Database.AllowsCallouts { public String query; global NFM621ControllerBatch() { //this.query = query; } global Database.QueryLocator start(Database.BatchableContext bc) { Date dateToday = Date.today(); return Database.getQueryLocator([select Id, Name,Employee_No__c,Stay_or_not__c,QuitDate__c,SendToComPlat__c from User where QuitDate__c <= :dateToday and Stay_or_not__c <> '已离职' and SendToComPlat__c <> true]); } global void execute(Database.BatchableContext BC, list scope) { List sobjectList = new List (); List userNewList = new List (); List idList = new List (); for (Sobject sobj: scope) { sobjectList.add(sobj.Id); } List userOldList = [select Id,SendToComPlat__c,PBI_Enable__c from User where Id In: sobjectList]; //List userOldList = scope; if (userOldList.size() > 0) { for (User userInfo : userOldList) { User userNew = new User(); userNew.Id = userInfo.Id; userNew.SendToComPlat__c = true; userNew.PBI_Enable__c = false; userNew.Stay_or_not__c = '已离职'; idList.add(userNew.Id); userNewList.add(userNew); } } System.debug('----------------'+userNewList); if (userNewList.size() > 0) { NFM621Controller.executefuture('', idList); update userNewList; } } global void finish(Database.BatchableContext BC) { } }