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), and understand profiles and permission sets at a basic level. You should also be able to read a simple SOQL query.
What ownership is
Every record in Salesforce has an owner, stored in the OwnerId field. The owner is a user or, on objects that support queues, a queue. Ownership is the starting point for record-level access, because every other sharing mechanism is defined relative to it.
Owners always have full access to their own records: they can read, edit, transfer and delete them, provided their object permissions allow those actions. Object permissions still apply, so an owner whose profile lacks Delete on Account cannot delete their own account.
Why ownership drives sharing
Org-wide defaults (OWD) describe what users who do not own a record can do with it. The role hierarchy then lets managers inherit access to what their subordinates own. Both depend on knowing who the owner is.
If you change the owner, the access changes with it. The new owner gets full access, and the managers above the new owner's role gain access through the hierarchy. Managers above the old owner lose that hierarchy access unless another mechanism still grants it.
Ownership and share rows
Salesforce records the reasons for access in share tables. An owner's access comes from the record itself, not from a share row, while access granted to others is stored as share rows. You can see these rows by querying the share object for a record:
SELECT Id, AccountId, UserOrGroupId, AccountAccessLevel, RowCause
FROM AccountShare
WHERE AccountId = '001XXXXXXXXXXXXXXX'The RowCause column tells you why each row exists. A row with the cause Owner represents the owner's access. Other causes include Team and Manual. A later chapter covers share tables in detail.
Changing the owner
You change ownership with the Change Owner action on a record, or by updating OwnerId in code or a data load. Note the following:
- Transferring a record can remove access that the previous owner had through ownership.
- On Account, the transfer settings can also move related records such as open opportunities, depending on the options you select.
- Manual shares that were granted by the previous owner are removed when ownership changes, unless the access is held by someone with another source of access.
Account acc = [SELECT Id, OwnerId FROM Account LIMIT 1];
User newOwner = [SELECT Id FROM User WHERE IsActive = true LIMIT 1];
acc.OwnerId = newOwner.Id;
update acc;Run this only in a sandbox. It reassigns a real record, and the query selects an arbitrary active user.
Common mistakes
- Treating ownership as the only way to get access. It is the strongest source, but sharing rules, teams and manual shares exist to open access beyond it.
- Assigning records to a generic integration user. Everyone above that user in the role hierarchy then sees all of those records.
- Forgetting that the owner still needs object permissions. Ownership grants record access, not the right to use the object.
Exercise
A sales rep owns an Account, and the Account OWD is Private. The rep's manager sits above them in the role hierarchy. Who can see the record, and what happens to the manager's access if the rep transfers the account to a rep in another branch of the hierarchy?
Show answer
The owner and the manager above them (through the role hierarchy, if Grant Access Using Hierarchies applies) can see it. After the transfer, the new owner gets access, and the managers above the new owner's role gain it. The original manager loses access unless another mechanism, such as a sharing rule or team membership, still grants it.