Hi David,
List<User> usersToUpdate = new List<User>();
for(User u : [Select id, IsActive from User where isActive=true and lastLoginDate <= :DATE.TODAY()-10]){
u.IsActive = false;
usersToUpdate.add(u);
}
if (usersToUpdate.size()>0){
update usersToUpdate;
}
There are some considerations to do this:
— one cannot deactivate self user record
— Cannot deactivate a user record which is referenced in another user record in a hierarchy custom field
— Make a Schedule Class apex and invoke via schedule UI in Salesforce.
Thanks