function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aruna Dhavaleswarapu 4Aruna Dhavaleswarapu 4 

Reverting the user email from .invalid after refresh

When sandboxes refresh, all users' email addresses have .invalid appended to them.
I am trying to revert all System Admin user emails to the correct one.

List<User> UserList = [SELECT id, email FROM User WHERE Profile.name = 'System Administrator' AND IsActive = True];
System.debug('Orginal List --->'+UserList);

for(User obj : UserList){
    obj.Email = obj.Email.removeEndIgnoreCase('.invalid');
      System.debug('email==>'+obj.Email);
    
}

if(UserList!= NULL && UserList.size() > 0)
{
    List<Database.SaveResult> SR = Database.update(UserList);
    
    for(Database.SaveResult srObj : SR){ 

      System.debug(srObj); 
    } 
    System.debug('Final User List ==>'+UserList);
}


While implementing this code from an anonymous block, I can see the changes in my debug log, though the users' email is not changed.

Can some expert guide me where I am going wrong