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
sanju21sanju21 

Assign records associated with one user account to another user

How can assign all the records associated with one user to another user before/after deactivating him? I tried to deactivate a user and it said it will direct to me some page wher I can chose the user to replace this user but it did not, it just deactivated. Now I am getting exception from reports where the deactivated user was the running user..please help.

Bhawani SharmaBhawani Sharma

You ca use System log to resolve this :

 

 

//Fetch all the accounts associated with InActive users
List<Account> listAccount = [Select OwnerId from Account where Owner.IsActive = false];

//fetch an active user from database
List<User> listUser = [Select Id from User where IsActive = true AND Profile.Name = 'System Administrator'];

//update owner id in fetched accounts records
if(listUser.size() > 0)
{
for(Account account : listAccount)
account.OwnerId = listUser[0].Id;
}

update listAccount;

 

Type the above script in System log and then execute it.