+ Start a Discussion
CBBsfdcCBBsfdc 

How to execute below code in anonymous window

Hi all 

How to execute below code in anonymous window   
 
public class UserUpdate {
   public void updateUser(List<ID> ids){
        Id userId = ids.get(0);

        Profile prf = [select id from Profile where Name='Work.com Only User'];
        User usr = [select IsActive,UserRoleId,ProfileId,Title,CompanyName,CallCenterId,DelegatedApproverId,ManagerId from User where id=:userId];
        usr.UserRoleId = null;
        usr.ProfileId = prf.id;
        usr.Title = null;
        usr.CompanyName = null; 
        usr.CallCenterId = null;      
        usr.DelegatedApproverId = null;
        usr.ManagerId = null;
        usr.IsActive = false;
        update usr;
        
    }
    }
Anonymous code is 
 
List<Id> Ids = new List<Id>();
Ids.add(id);
UserUpdate.updateUser(Ids);

kindly Support and Suggest

Thanks ​​​​​​​
Alfredo Puente VasconcelosAlfredo Puente Vasconcelos
You can try this:

UserUpdate userUpdate = new UserUpdate();
userUpdate.updateUser(Ids);
Raj VakatiRaj Vakati
Try this
 
Map<Id,User> amps = new Map<Id,User>([select Id from User limit 3]);
List<Id> Ids = new List<Id>();
Ids.addAll(amps.keySet());
UserUpdate.updateUser(Ids);

 
Ajay K DubediAjay K Dubedi
Hi,
If you are not using a static method then you have to make reference for the above class.because you can not call a non-static method with a class name.
Try the below code-
   
  List<Id> ids = new List<Id>();
  ids.add('0050o00000Vw710AAB');
  UserUpdate usr = new UserUpdate();
  usr.updateUser(ids);

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi