环境设置对应的job 执行时间
global class UpdateAccountSegmentationScheduler implements Schedulable{
global void execute(SchedulableContext sc) {
Integer month=Date.today().month();
UpdateAccountSegmentationBatch batch = new UpdateAccountSegmentationBatch();
database.executeBatch(batch);
}
}
Batch
global class UpdateAccountSegmentationBatch implements Database.Batchable<sObject>{
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([
SELECT Id, Name, Customer_Segmentation__c, Type,
(SELECT Id, EffectiveDate, AccountId, TotalAmount
FROM Orders)
FROM Account
]);
}
global void execute(Database.BatchableContext bc, List<Account> scope) {
****
update scope;
}
global void finish(Database.BatchableContext bc) {
System.debug(recordsProcessed + ' records processed.');
}
}