You need to sign in to do that
Don't have an account?
Dritter
Batch Scheduler
Below is a scheduler that fires a batch class to deactivate portal users and licensed users that haven't logged in in the last 90 days. I want it to process the list of users in batches of 150 "database.executebatch ((ucu), 150);", but it seems to be doing it in batches of 1000. For example, my queue pulled back 1700 users that needed to be deactivated and in Salesforce it shows it was processed in 2 batches. Any ideas why it's not doing 150 per batch?
Scheduler:
Batch Class:
Scheduler:
global class KapUserCleanUpScheduler implements Schedulable{ public static String CRON_EXP = '0 0 0 3 9 ? 2022'; global void execute(SchedulableContext BC) { KapUserCleanUp ucu = new KapUserCleanUp (); database.executebatch ((ucu), 150); } }
Batch Class:
global class KapUserCleanUp implements Database.Batchable<sObject>{ datetime myDateTime = datetime.now(); //datetime newDateTime = myDateTime.addDays(-1); datetime inactiveDateTime = myDateTime.addDays(-90); //System.debug('current time: ' + myDateTime); //System.debug('newDateTime time: ' + newDateTime); //System.debug('inactiveDateTime time: ' + inactiveDateTime); global Database.querylocator start(Database.BatchableContext BC){ return Database.getQueryLocator([SELECT Email,Id,LastLoginDate FROM User WHERE (IsPortalEnabled = True AND IsActive = true AND CreatedDate = YESTERDAY) OR (IsPortalEnabled = false AND isActive = true AND lastLoginDate < :inactiveDateTime AND LastName != 'Site Guest User')]);} global void execute(Database.BatchableContext BC, List<User> users){ System.debug('Users retrieved ' + Users); for (User u : users) { u.isActive = false; System.debug(u.id + ' ' + u.email + ' will be deactivated' + u.lastLoginDate); } Database.SaveResult[] srList = Database.update(users, false); for (Database.SaveResult sr : srList){ if (!sr.isSuccess()) { //Operation failed, so get all errors for(Database.Error err : sr.getErrors()){ System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); } } } } global void finish(Database.BatchableContext BC){ } }