You can do the updation in user object, before that you have to think of which users based on some conditions, you need to update as active.
So, you need to get the user list those who are inactive.
List<User> inactiveUsers = [SELECT Id,name,ProfileId,IsActive FROM User WHERE isActive =: false ];
List<Users> ModifiedUsersList = new List<Users>();
if(inactiveUsers.size() > 0){
for(User u : inactiveUsers){ //Check the condition for the users whom you are going to make active again. If you are going to make the all the users active those who are inactive you don't need this IF condition here if(u.id == <your id to check here> || u.ProfileId == <check profile>){ u.isActive = true; ModifiedUsersList.add(u); } } update ModifiedUsersList; }
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
Rather than pulling a list of all inactive users and then looping through them to find the ones you want to update, you should be able to add conditions in your query to pull exactly the users that you wish to update. This should make your code more efficeint. Also, I would be careful using IDs as criteria, because they will differ between your sandbox and production environments.
It might be helpful if you explained the criteria that you are using to determine which users to activate. Then, we can determine exactly what SOQL query you need to get the correct list of users.
Try this
Try this code. This can be used for bulk records. You can accept this as a solution if this solves your problem.
List<User> user_list = [Select id,isActive from user where isActive=False];
List<User> new_Users = new List<User>();
For(User u : user_list)
{
u.isActive = True;
new_Users.add(u);
}
update new_Users;
Hi Ezil,
You can do the updation in user object, before that you have to think of which users based on some conditions, you need to update as active.
So, you need to get the user list those who are inactive.
List<User> inactiveUsers = [SELECT Id,name,ProfileId,IsActive FROM User WHERE isActive =: false ];
List<Users> ModifiedUsersList = new List<Users>();
if(inactiveUsers.size() > 0){
for(User u : inactiveUsers){
//Check the condition for the users whom you are going to make active again. If you are going to make the all the users active those who are inactive you don't need this IF condition here
if(u.id == <your id to check here> || u.ProfileId == <check profile>){
u.isActive = true;
ModifiedUsersList.add(u);
}
}
update ModifiedUsersList;
}
Hope so this helps you...!
Please mark this answer a Solution and please give kudos by clicking on the star icon, if you found this answer as helpful.
Rather than pulling a list of all inactive users and then looping through them to find the ones you want to update, you should be able to add conditions in your query to pull exactly the users that you wish to update. This should make your code more efficeint. Also, I would be careful using IDs as criteria, because they will differ between your sandbox and production environments.
It might be helpful if you explained the criteria that you are using to determine which users to activate. Then, we can determine exactly what SOQL query you need to get the correct list of users.