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
vutukuru balajivutukuru balaji 

how to change owner of record using trigger when we are deactivating the current owner ?

hi i have a task when we deactivating a user,the ownership of all the records owned by this user has to changed to his manager by using trigger.can any body please help for the code that need to be write for the trigger
Ankit AroraAnkit Arora
Here I hope we are not talking about a single object. There must be multiple records from multiple objects which are owned by current user. So either can use SOSL or you've to write SOQL on all those object in same class. This is all done via trigger on USER.

Once you've the results, you've to loop over it and change the owner of it. Or if there are possibilities of having records in bulk then you can use batch as well.
vutukuru balajivutukuru balaji
suppose user had records in  account only then tell me the trigger code to change owner name.