Apex managed sharing and share objects
When declarative sharing can't express a requirement, how to write share rows with the right RowCause and AccessLevel, keep them correct with recalculation classes, check a user's real access with UserRecordAccess, and choose the right sharing keyword for each class.
Given a scenario, justify using sharing objects and Apex managed sharing.
~7 min read · 15 practice questions ·
What the exam expects
- Justify Apex managed sharing over sharing rules and the role hierarchy for a given requirement, and spot when no share object exists.
- Write share rows with a valid
AccessLevelandRowCause, and predict what happens to them on owner and org-wide default changes. - Build a sharing recalculation class and design group-based shares that scale.
- Check a user's effective access to a record with
UserRecordAccess. - Pick
with sharing,without sharingorinherited sharingfor a class from how it is called.
Key terms: share object (AccountShare, MyObject__Share: the access list rows for a record), RowCause (the sharing reason, which decides who can change the row), Apex sharing reason (a developer-defined RowCause on a custom object), AccessLevel (Read or Edit granted by the row), UserRecordAccess (read-only object reporting a user's effective access).
Key facts
- Detail
Manual; only Manual rows are deleted on owner change
AccessLevel values- Detail
Read,Edit;Allcan't be granted
- Detail
- Access not above the org-wide default fails with
FIELD_FILTER_VALIDATION_EXCEPTION
- Detail
- Custom objects only
- Detail
- Only
Manual
- Detail
- Runs the object's recalculation classes; removes redundant shares
- Detail
- Read-only; up to 200 record IDs; ignores restriction rules
- Detail
- Runs without sharing
Sources for this section (6)
- Sharing a Record Using Apexdeveloper.salesforce.com (opens in a new tab)
- Understanding Sharingdeveloper.salesforce.com (opens in a new tab)
- AccountSharedeveloper.salesforce.com (opens in a new tab)
- Recalculating Apex Managed Sharingdeveloper.salesforce.com (opens in a new tab)
- UserRecordAccessdeveloper.salesforce.com (opens in a new tab)
- Sharing Keywordsdeveloper.salesforce.com (opens in a new tab)
- Why is a new `Read` share rejected after an object's default changes to Public Read Only?
- When should a service class be declared `inherited sharing` rather than left without a keyword?
- Why can't code insert `Order_Line__Share` when Order_Line__c is a detail object?
- Which group type keeps Apex role shares away from partner users after digital experiences are enabled?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer II pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 28 lessons of the Platform Developer II guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (15 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams