Salesforce Security: Apex Sharing on Standard Objects lost on Owner Change (in English)
Updated 2026-11-07
What's changed since the video
Each change is dated and checked against Salesforce's own documentation.
- Standard objects can have their own sharing reasons now. The answer in the video was a trigger that puts the shares back. Salesforce's Developers blog, October 2026: "For over a decade, standard objects didn't support custom row causes," and now they do, rolling out to all orgs by the end of October 2026 (Protect Apex Shares: Custom Row Causes on Standard Objects, Salesforce Developers blog, checked 2026-11-07). For standard objects, you "create them using the Metadata API or Tooling API" (Sharing a Record Using Apex, Apex Developer Guide, Winter '27, checked 2026-11-07).
- Manual shares can be kept. Since Winter '27, the Keep manual shares when transferring records setting keeps them through an owner change (Keep Manual Shares When Transferring Records, Salesforce Help, checked 2026-11-07).
- The account team can be kept. In the demo, the team member added by code went too. When you change the owner, "select Keep account team" to keep it; that "only applies to team members added by a Salesforce admin, the account owner, or someone higher in the role hierarchy" (Considerations for Changing a Record's Owner, Salesforce Help, checked 2026-11-07).
Still right
- The question from a student in class: if code on a standard object has to use the Manual sharing reason, won't those shares be lost when the owner changes? The demo answers it with three users: an admin, one user who gets the share, and one who doesn't.
- By default, a manual share is deleted when the owner changes, and so is a share written by code with the Manual reason.
- Code can't write a share with another built-in reason, such as Team.
- On a custom object, a sharing reason of your own keeps code's shares through an owner change.
- Anyone using code to share standard objects has to plan for owner changes.
All videos in this series: Tietoturva-arkkitehtuuri
Video ladataan YouTubesta vasta, kun napsautat sitä.