Sub topic 2
Record Ownership and Why It Drives Sharing
This chapter assumes you can navigate Setup, know the standard objects (Account, Contact, Opportunity, Case), understand profiles and permission sets at a basic level, and can read simple SOQL. You do not need to know org-wide defaults or roles yet. Later chapters cover them, and this chapter explains the ownership that they build on.
What record ownership is
Almost every record in Salesforce has an owner. The owner is stored in the OwnerId field. It holds the ID of either a user or a queue. Ownership is more than a label. Salesforce uses it as the starting point for every record-level access decision.
The owner of a record can always see it. Which other users can see it depends on what the org does next: the org-wide default for the object, the owner's place in the role hierarchy, and any extra sharing. All of these are measured from the owner. If you change the owner, you change who can see the record.
Why ownership drives sharing
Record access in Salesforce is a set of additions. Each mechanism grants access, and none of the normal mechanisms removes it. The owner is the foundation of that structure.
- The owner gets the highest level of access to the record. For most objects that means read, edit, transfer and delete, subject to object permissions.
- When the org-wide default is Private, the owner is often the only user with access, apart from users who bypass sharing.
- The role hierarchy is read from the owner upward. Users in roles above the owner's role can get access because of the owner's position.
- Sharing rules can be based on who owns a record. An owner-based rule shares records owned by a given role or group with another role or group.
The result is that the question "who owns this record?" is usually the first thing to ask about a record someone cannot see.
Who can own a record
Ownership has a few rules that depend on the object.
- Most standard objects, such as Account, Opportunity and Lead, can be owned by an active user.
- Lead and Case can also be owned by a queue. A queue is a holding area for records that a group of users picks up. Custom objects can use queues if you enable them for that object.
- Some objects cannot have an owner of their own. A child record in a master-detail relationship, such as a detail record, takes its access from its master record. Contact is a related case. When a Contact is linked to an Account, its sharing can be controlled by the Account, depending on the setup.
- A user must be active to receive records. Records owned by inactive users still exist, and the sharing calculated for them remains in place.
Check the object's documentation if you are unsure, because the rules differ between standard objects.
Master-detail and ownership
In a master-detail relationship, the detail record has no OwnerId field. Its sharing, its owner-related access and its record-level security come from the master record. If you need independent owners and sharing on both objects, use a lookup relationship instead. This is a common design decision, and it is hard to reverse once data exists.
Ownership and the other access layers
Ownership only matters after the object-level check passes. Salesforce checks in this order.
- Object permissions. Does the user's profile or permission sets grant Read, Create, Edit or Delete on the object?
- Record access. Does ownership, the org-wide default, the hierarchy or other sharing let the user reach this specific record?
A user must pass both. An owner who loses Read access to the object through a profile change cannot see their own records, because the object permission stops the request first.
| Situation | Result |
|---|---|
| Owner, with object Read and Edit | Can view and edit the record |
| Owner, with no object Read | Cannot see the record |
| Non-owner, object Read, org-wide default Private, no other sharing | Cannot see the record |
| Non-owner, object Read, org-wide default Public Read Only | Can view, cannot edit |
Transferring ownership
You change the owner by editing the Owner field on the record, or by using the Change Owner action on lists and in mass transfer tools. A transfer has effects that surprise people.
- Previous owner's access. The old owner does not keep access automatically. After the transfer, the old owner keeps access only if the org-wide default, the hierarchy or another sharing mechanism grants it. Some transfer tools offer a "keep access" option. Treat that option as a convenience, because it creates a manual share.
- Hierarchy. Users above the new owner's role gain access. Users above only the old owner's role may lose it.
- Related records. Transferring an Account can also transfer open Opportunities and Cases, depending on the options chosen and who has access. Read the confirmation screen before you accept.
- Sharing rules. Owner-based rules recalculate for the new owner. Sharing rules and team access that depended on the old owner may be removed.
- Recalculation. Large transfers can trigger sharing recalculation and take time.
A transfer can also fail. The new owner must have Read access to the object, and in some cases Create access for the transfer to complete.
Seeing ownership in data
Ownership appears as OwnerId in SOQL. You can follow the relationship to get the owner's name and role.
SELECT Id, Name, OwnerId, Owner.Name, Owner.UserRole.Name
FROM Account
ORDER BY Name
LIMIT 20This query shows who owns each account and where that owner sits in the role hierarchy. Owner.UserRole.Name can be null if the owner has no role. A user without a role is outside the hierarchy, so nobody gains access through that owner's position.
To see how ownership shows up in sharing data, query the share table for an account.
SELECT Id, AccountId, UserOrGroupId, AccountAccessLevel, RowCause
FROM AccountShare
WHERE AccountId = '001XXXXXXXXXXXXXXX'The owner appears as a row with RowCause set to Owner. The AccountAccessLevel for that row is All. Other rows show other reasons, such as Team or Manual. The next chapters cover share tables in detail. For now, remember that the owner's access is recorded as a share row with the cause Owner. For some objects, with a Private default, that row may not be visible in the share table. The UserRecordAccess object gives a reliable answer for a single user and record.
SELECT RecordId, HasReadAccess, HasEditAccess, HasDeleteAccess
FROM UserRecordAccess
WHERE UserId = '005XXXXXXXXXXXXXXX'
AND RecordId = '001XXXXXXXXXXXXXXX'Common mistakes
- Treating ownership as a permission. Being the owner does not bypass object permissions. Profiles and permission sets still apply.
- Assigning records to a generic user. This creates a hierarchy that does not match how the business works.
- Forgetting about inactive owners. Records owned by deactivated users stay in the system, and their access follows the old owner's role position. Reassign them.
- Expecting a transfer to be neutral. Ownership changes alter who can see the record. Test with a sample record before a mass transfer.
- Choosing master-detail without considering sharing. The detail record cannot have its own owner.
Exercise
An Opportunity is owned by Priya, who has the Sales Rep role. Priya's manager, Marco, holds a role above hers. The Opportunity org-wide default is Private, and there are no sharing rules. A colleague, Dana, is in a different branch of the hierarchy. Dana has Read permission on Opportunity. Who can see the record, and what happens to access if the record is transferred to Dana?
Show answer
Priya can see it because she is the owner. Marco can see it because his role is above the owner's role and the hierarchy is in effect. Dana cannot see it, because the default is Private, she is not the owner, and she is not above Priya in the hierarchy. After the transfer to Dana, Dana is the owner and can see it. Priya loses owner access and can see the record only if another mechanism grants it. Marco keeps access only if he is above Dana's role. If he is not, he loses it.
Exercise
A user's profile is changed so that it no longer has Read access to Account. The user still owns 40 accounts. Can the user see those accounts? Why?
Show answer
No. Object permissions are checked first. Without Read on Account, the user cannot view any account record, including ones they own. Ownership affects record-level access only after the object-level check passes.