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<Sobject> scope) {
|
List <String> sobjectList = new List <String> ();
|
List <User> userNewList = new List <User> ();
|
List <String> idList = new List <String> ();
|
for (Sobject sobj: scope) {
|
sobjectList.add(sobj.Id);
|
}
|
List <User> userOldList = [select Id,SendToComPlat__c,PBI_Enable__c from User where Id In: sobjectList];
|
//List <User> 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) {
|
|
}
|
}
|