title: Cannot modify a collection while it is being iterated.- Apex class
body: <p>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."</p>
  
  <p>Here is my apex code:</p>
  
  <pre><code>public class ActivateUsers
  {
  
  @InvocableMethod
  public static void ActivateUser(List&lt;user&gt; Users)
  {
         list&lt;user&gt; userslist= new list&lt;user&gt;();
  
         for(user u: Users)
  
         {
            u.isActive=true;
            userslist.add(u);
  
  
         }
  
         update userslist;
  
       }
   }
  </code></pre>
  
  <p>I know what the issue is, just don't know how to resolve it, considering what I am trying to do. </p>
  
  <p>Thanks</p>