+ Start a Discussion
chvl narayanachvl narayana 

I can we change owner if Owner is inActive

Hii all
Hope you are doing good

I have a two users. user1 and User2
User2 is manager to User1.
User1 have created some records. If user1 isActive is false,
Manager will be the record owner.

I Write code like this
trigger RecordOwnerChangeEx on User (after update) {   
 list<user> u=[select id, isActive, ManagerId from user where id in:trigger.new];
  // list<account> acc=[select id, ownerId from Account where ownerId in: ids ];
    list<account> ac=new list<account>();
    for(User uu:u){
        if(uu.IsActive == false && uu.ManagerId != null){
        for(account a:[select id, ownerId from Account where ownerId =:uu.id ]){
            a.ownerId = uu.ManagerId;
    update ac;
Shukla YogeshShukla Yogesh

Hi Narayana,

This can be done using Process Builder and Flows. The idea would be this:

1. Create a Process on the User object.
2. Fire it when a user record is marked inactive.
3, Launch a Flow.
4. Pass this user's ID into a Flow variable.
5. Within the Flow, find all accounts that have the Account Owner ID = Passed in User ID
6. Mass Reassign the found accounts to deactivated user's manager.

For the flow part of the implementation, you can take cues from the following link(Reassign Accounts):

Dutta SouravDutta Sourav
Hi Narayana,
I would recommend to use Mass Transfer for transferring Account from user1 to user2. 

Set Up>Data Management> Mass Transfer Records>Transfer Accounts.
User-added image
Hope this helps!

Best Regards,