Sub topic 9
Sharing a Single Record Manually
This chapter assumes you know record ownership, org-wide defaults (OWD), and the role hierarchy from earlier chapters. It also assumes you can read basic SOQL. Manual sharing is the tool for one-off exceptions: one record, one person or group, one decision made by a human.
What manual sharing is
Manual sharing lets a user grant access to a single record that they are allowed to share. It is done from the Sharing button on the record detail page. The grant is stored as a row in the object's share table with the row cause Manual. You will see share tables in more detail in a later chapter.
Manual sharing can only open access. It cannot reduce access below what OWD, ownership, the role hierarchy, or sharing rules already give.
Who can share a record
A user sees a working Sharing button only if they meet one of these conditions:
- They own the record.
- They are above the owner in the role hierarchy, and the object has Grant Access Using Hierarchies enabled.
- They have the Modify All object permission, or the Modify All Data system permission.
- They have Full Access to the record, for example through a team or an earlier share.
Having Read or Edit access is not enough. A user who can only edit a record cannot share it.
The Sharing button also needs the object's OWD to be Public Read Only or Private. If the OWD is Public Read/Write (or Controlled by Parent for a detail record), there is no restriction to open, so the button does not appear for those access levels. For Public Read Only, you can still grant Read/Write by manual share.
Granting a manual share in the UI
- Open the record and click Sharing.
- Click Add.
- Choose what to share with: public groups, roles, roles and subordinates, queues, or users. The list depends on your org configuration.
- Select the targets and move them to the selected list.
- Pick an access level for each: Read Only or Read/Write. Full Access is not available here for custom objects. Some standard objects offer extra levels for related records, such as account sharing with contacts, opportunities, and cases.
- Click Save.
The Sharing Detail page then lists every share on the record, including the new Manual one.
What manual sharing does not do
- It does not bypass object permissions. If the target user's profile or permission sets lack Read on the object, the share has no effect on what they can open.
- It does not bypass field-level security. Hidden fields stay hidden.
- It does not give Delete or transfer rights. Access levels are Read or Read/Write only.
- It does not scale. Granting hundreds of shares by hand is hard to audit and easy to forget.
When manual shares are removed
Manual shares are fragile by design. They are deleted automatically in these cases:
- The record owner changes. Manual shares are dropped when ownership is transferred, because the share was granted by or on behalf of the old owner. This is the most common surprise.
- The OWD becomes more permissive so that the share is redundant (for example, Private changed to Public Read/Write). The share rows are cleaned up during recalculation.
- The user who shared removes it, or an admin removes it, from the Sharing Detail page.
- The target is deleted or deactivated in a way that removes the user or group.
Manual shares are not removed by a change in the sharing user's own role. They persist until one of the cases above occurs.
Because of the ownership rule, manual sharing is a poor choice for access that must survive reassignment. Use a sharing rule or a team instead.
Inspecting manual shares with SOQL
Each object with a Private or Public Read Only OWD has a share object. For a custom object Invoice__c, it is Invoice__Share. Standard objects use names like AccountShare and OpportunityShare.
This query lists every share row on one record:
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause
FROM Invoice__Share
WHERE ParentId = '<invoice record Id>'The fields mean:
| Field | Meaning |
|---|---|
| `ParentId` | The record being shared |
| `UserOrGroupId` | The user or group that receives access |
| `AccessLevel` | `Read` or `Edit` (and `All` for the owner's own row) |
| `RowCause` | Why the row exists, such as `Owner`, `Manual`, or `Rule` |
To see only manual grants, add AND RowCause = 'Manual'. The owner's row, with row cause Owner, always exists for a Private record and cannot be edited or deleted.
Note that UserOrGroupId points to a user or to a group. For role-based and public group targets it holds the Id of a group record that Salesforce maintains internally, not the role Id. Use the Group object to resolve it, with Type values such as Role, RoleAndSubordinates, and Regular.
Granting a manual share with Apex
The same row can be created in code. Setting RowCause to Manual produces the equivalent of using the Sharing button, so the share follows the same removal rules.
Invoice__Share share = new Invoice__Share();
share.ParentId = invoiceId;
share.UserOrGroupId = userId;
share.AccessLevel = 'Read';
share.RowCause = Schema.Invoice__Share.RowCause.Manual;
Database.SaveResult result = Database.insert(share, false);
if (!result.isSuccess()) {
System.debug(result.getErrors()[0].getMessage());
}Points to notice:
Database.insert(share, false)allows partial success and returns a result instead of throwing. InspectisSuccess()for each record when you insert in bulk.- The code runs with the permissions of the running user. The running user must be allowed to share the record, under the same rules as the UI. Code running in system context, for example a class declared
without sharing, can write the row regardless of the running user's own access. - Apex sharing with a custom row cause is different. Custom row causes survive owner changes, and only code or an admin removes them. The row cause is defined on the object's Apex Sharing Reasons list. That is covered in the Apex sharing chapter.
A common failure is INVALID_CROSS_REFERENCE_KEY or FIELD_INTEGRITY_EXCEPTION when the target user or group Id is wrong, inactive, or a user who cannot see the object. Another is INSUFFICIENT_ACCESS_OR_READONLY when the running user cannot share the record.
Edge cases
- Redundant shares. If a user already has equal or higher access through the role hierarchy or a rule, adding a manual share is harmless but unnecessary. Salesforce may keep the row, but the user's effective access is the highest of all sources.
- Public Read/Write OWD. There is no share table needed for the object, and the Sharing button does not apply.
- Groups. Sharing with a public group gives access to all current and future members. Sharing with "Roles and Subordinates" includes later additions to that part of the hierarchy.
- Parent-controlled objects. A detail record in a master-detail relationship has no Sharing button of its own. Its access follows the parent. Share the parent instead.
- Sharing a parent account. The account Sharing page can also set access to the account's contacts, opportunities, and cases, according to the available options.
Choosing manual sharing
Use it when:
- the need is a one-time exception,
- a person decides who gets access, case by case,
- losing the share on reassignment is acceptable.
Choose another mechanism when the rule can be stated as "records owned by X" or "records where field Y equals Z" (sharing rules), when a group of people works on one account regularly (teams), or when code must create and maintain the grant (Apex sharing).
Exercise
A sales manager manually shares an invoice with a finance analyst at Read Only. Two weeks later the invoice is reassigned to a different owner. The analyst reports they can no longer open it. Why, and what should the admin change so the access survives future reassignments?
Show answer
Changing the record owner removes manual shares on that record, so the analyst's Manual row was deleted. To keep access across reassignments, replace the manual share with a sharing rule, for example a criteria-based rule that shares invoices matching a field value with the analyst's public group. A team or an Apex share with a custom row cause also survives owner changes.
Exercise
Write a SOQL query that returns only the manual shares on one Invoice__c record, and say what you would expect to see in the RowCause column.
Show answer
SELECT Id, ParentId, UserOrGroupId, AccessLevel, RowCause FROM Invoice__Share WHERE ParentId = '<invoice record Id>' AND RowCause = 'Manual'. Every returned row has RowCause equal to Manual. The owner's Owner row and any rule-based rows are excluded.