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
Pradeep Pradhan 21Pradeep Pradhan 21 

Write an apex program, to DeActivate the User Based on the Specified UserName.

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Pradeep,

You can write the Apex class as below.
 
public class DeactivateUser {
    List<User>ulist= new List<User>();
    public void deactiveuser(String Username){
        for (User u:[Select id,UserName,IsActive from user where UserName=:Username]){
            u.IsActive=false;
            ulist.add(u);
        }
        update ulist;
    }

}

You need to send the userName as the input for the method while calling as shown below.
 
DeactivateUser de= new DeactivateUser();
de.deactiveuser('assaample@gmail.com');

If this solution helps, Please mark it as best answer.

Thanks,