I am calling an apex class from flow. Inside the apex class, I am trying to activate the user. But I am getting the "Cannot modify a collection while it is being iterated."
Here is my apex code:
public class ActivateUsers
{
@InvocableMethod
public static void ActivateUser(List<user> Users)
{
list<user> userslist= new list<user>();
for(user u: Users)
{
u.isActive=true;
userslist.add(u);
}
update userslist;
}
}
I know what the issue is, just don't know how to resolve it, considering what I am trying to do.
Thanks