You need to sign in to do that
Don't have an account?
shan141
deactivate user profiles using apex code
Hi,
In our organization we have 2000 users, I want to deactivate all the users except Administrator profile users.
How can I achieve this with peace of Apex code (for automation). If possible Could anyone please provide peace of code to achieve this and how to execute that code.
Thanks in advance
sha
You can export all the users via dataloader and then change the active field to false and update it back in...
Very easy no code...
Thanks
eTechCareers
You can run the following code snippet from the System log to deactivate the users
//get your corresponding user roleId
List<User> users = [Select IsActive, UserRoleId, UserRole.Name from User where UserRoleId not in ('00EA0000000DsjTMAS')];
List<User> lstUsers = new List<User>();
for(User u: users)
{
u.IsActive = false;
lstUsers.add(u);
}
upsert lstUsers;