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

Mass Re-Assign records from Owner whos going to be de-activated to his manager

Hey All

just a quick question

Aim – User  is leaving the organisation, so i need to deactivate the user, before de-activating i want to assign all his records example leads & opportunities to his manager .

I want to achieve all this via code instead of using the data loader.

Is this viable ? 


how many records do you have for each type ?


HI the records can vary depending on the user we trying to de-activate

In most instances the avg would be around 1000
So lets say your  the user i want to de-activate, i want to assign your 1000 leads to your manager 


With these data volume this must be not too hard running some apex anonymously.


Example :


List<Contact> contactList = [select OwnerId from Contact where OwnerId='005U0000001VVmp'];
for (Contact currentContact : contactList) {
	currentContact.OwnerId = '005U0000000KwE9';
update contactList;


Alternative :


Use this third party tool supporting direct Update command like standard SQL


HI Twan


Thank you for your response

In this example you can see that “Jim Smith” has been de-activated. What i want to do, is when you press save, an apex trigger  is triggered and re-assign “Jim Smith” Leads into this appropriate manager

Can this be done ?


You can try to embed my example code in a trigger.

HI twan

I am new to code so my apologises, i try and work on it over the weekend