6

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.

2
  • Are you doing this by apex or API ? Commented Mar 20, 2014 at 12:47
  • 1
    You might be able to determine all records owned by a user by inspecting the UserRecordAccess table. Transferring them will be more complex.
    – Phil Rymek
    Commented Mar 20, 2014 at 20:43

2 Answers 2

4

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.

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .