Notes
Apex:
global class DeactivateInactiveSystemAdmin implements Schedulable {
global void execute(SchedulableContext sc) {
deactivateInactiveSystemAdmin();
}
private void deactivateInactiveSystemAdmin() {
Integer inactivityDaysThreshold = 30;
List<User> inactiveAdmins = [SELECT Id, LastLoginDate FROM User WHERE Profile.Name = 'System Administrator' AND IsActive = true AND LastLoginDate < LAST_N_DAYS : inactivityDaysThreshold];
for (User admin : inactiveAdmins) {
admin.IsActive = false;
}
update inactiveAdmins;
}
}
Code to schedule the Schedulable class
String jobName = 'DeactivateInactiveAdminJob';
String cronExp = '0 0 0 * * ?';
DeactivateInactiveSystemAdmin jobInstance = new DeactivateInactiveSystemAdmin();
System.schedule(jobName, cronExp, jobInstance);
Flow Builder:
Video
Video does not exists.