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
CBNCBN 

How to Execute in anonymous window for below code

Hi All,

How to excute below code in Anonymous window 
 
public class UserUpdate {

    public static void updateUser(List<ID> ids){
    Id taskId = 'aAY2h0000004CANGA2';
       
       delete [SELECT Id from PermissionSetAssignment where AssigneeId=:userId and PermissionSet.ProfileId=null];
       delete [Select Id  from GroupMember where UserOrGroupID=:userId];
       delete [SELECT Id FROM UserPackageLicense where UserId=:userId];     
        
        Profile prf = [select id from Profile where Name='ServiceDesk Client'];
        User usr = [select IsActive,UserRoleId,ProfileId,Title,ManagerId from User where id=:userId];
        usr.UserRoleId = null;
        usr.ProfileId = prf.id;
        usr.Title = null;
        usr.ManagerId = null;
        usr.IsActive = false;
        update usr;
        
    }
    }

Kindly Support and suggest

Thanks 
Murali VijayMurali Vijay
Try UserUpdate. updateUser( Pass List of IDs);
GovindarajGovindaraj
Hi,

We can execute below code in anonymous window like below,
UserUpdate. updateUser(List of IDs);
But, i have below questions on the code,
1. From where are we getting the value for variable 'userId' ?
2. I could see the variable 'ids' is not used anywhere

Thanks,
Govindaraj.S
Ajay K DubediAjay K Dubedi
Hi,
 - You have to pass List of ids as a parameter of the method.
 - A static method is called by class name so you need to execute the above code from the execute anonymous-
   
     List<Id> ids = new List<Id>();
     ids.add(id); //push ids on the list
     UserUpdate.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