Find your content:

Search form

You are here

Query to Identify all records owned by a User

 
Share

Is there any query which ca n retrieve all the records owned by a user.

We have a request to transfer all the records owned by User A to User B.

We have lot of custom objects, so i was wondering if there is a query to retrieve all records owned by a User.


Attribution to: user5352

Possible Suggestion/Solution #1

When it comes to transferring ownership of records, you will want to ensure that you properly get child objects and be aware of some of the side effects of transferring, such as:

When transferring accounts and their related data in Professional, Enterprise, Unlimited, Performance, and Developer Editions, all previous access granted by manual sharing, Apex managed sharing, or sharing rules is removed. New sharing rules are then applied to the data based on the new owner. The new owner may need to manually share the transferred accounts and opportunities as necessary to grant access to certain users.

Spend some time reading up on some of that so you don't have any issues. Once you are ready to do the transfer, you will be much better served using the built in Salesforce tool for mass transferring records then attempting to do this through direct data manipulation with SOQL and DML. Some objects will have additional options when changing ownership that SOQL/DML will not take into account as well.


Attribution to: Jesse Altman

Possible Suggestion/Solution #2

You will need to use a separate query for each of your custom objects that is not a child in a master-detail relationship. So depending on the relationship types between your objects, that could be all your custom objects or just a few of them.

You can re-use the code for all the custom object types by using dynamic SOQL where the object name is varied from a list of object names.

If you want to go on and update the Owner to the new User then you will probably end up using a Batchable (if you are working in Apex) to stay within governor limits.

Obviously note Jesse Altman's point about researching side effects; I'm not sure what they might be for custom objects.


Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/30562

My Block Status

My Block Content