+ Start a Discussion
shan141shan141 

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

imuino2imuino2

Try this, you cant delete users by dml.

All i could find is to get the user as not active by setting IsActive flag to false.

List<User> u = [Select Id, IsActive From User];
for (User user : u){
    user.IsActive = true;
}