{"id":1596,"date":"2026-09-09T13:00:00","date_gmt":"2026-09-09T07:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/"},"modified":"2026-09-09T13:00:00","modified_gmt":"2026-09-09T07:30:00","slug":"apex-managed-sharing-share-records","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/","title":{"rendered":"Apex Managed Sharing: Share Records with Code"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex Managed Sharing lets your code give a user or group access to a record when sharing rules cannot express the rule. For example, a course should be shared with the instructor named in a lookup field, and that access should move when the instructor changes. Sharing rules cannot read a lookup to a user, but Apex can.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will learn share objects, the RowCause field, Apex sharing reasons and how to keep shares in sync with a trigger. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-sharing-rules-roles-owd\/\">Salesforce sharing rules, roles and OWD<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-sharing-keywords-with-without-inherited\/\">Apex sharing keywords<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-crud-and-fls-user-mode\/\">Apex CRUD and FLS<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Apex Managed Sharing?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Managed Sharing is record sharing created by Apex code, using a special share object and an Apex sharing reason. Every custom object with a Private or Public Read Only org-wide default has a share object, such as Course__Share. Each share row says which user or group gets which access to which record, and why.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a guest list at a wedding. The owner of the hall decides who enters. A share row is one name on the list, with a note saying &#8220;family&#8221; or &#8220;photographer&#8221;. When plans change, you remove names with that note, without touching the others.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Apex Managed Sharing Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some access rules depend on data that sharing rules cannot read. Here is why Apex Managed Sharing matters at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, each course has an Instructor__c lookup to a user who must edit it.<\/li>\n\n<li>Also, instructors change during a term, so access must move with them.<\/li>\n\n<li>Next, criteria-based sharing rules cannot share with a user named in a field.<\/li>\n\n<li>Access must survive an owner change, unlike manual sharing.<\/li>\n\n<li>Finally, you need a clear reason on each share for audits.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So Apex Managed Sharing fills the gap between declarative sharing and business rules.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Apex Managed Sharing Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex Managed Sharing follows a simple cycle. First, an admin creates an Apex sharing reason on the object, such as Instructor. Next, a trigger or service builds Course__Share rows with the record Id, user Id, access level and that reason. Then the code inserts those rows. After that, Salesforce grants the access and shows the reason on the record&#8217;s sharing page. Finally, when the instructor changes, the code deletes rows with that reason and inserts new ones.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-1-1024x640.png\" alt=\"Apex Managed Sharing diagram showing sharing reason, share rows, insert, access and re-sharing\" class=\"wp-image-1594\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How Apex shares a course with its instructor.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Share Objects<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Custom object shares are named ObjectName__Share, such as Course__Share. Standard objects use names such as AccountShare and OpportunityShare.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Share Fields<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A custom share row has four key fields: ParentId for the record, UserOrGroupId for the user or group, AccessLevel and RowCause.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Access Levels<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">AccessLevel can be Read or Edit for Apex shares. Full Access comes only from ownership and the role hierarchy, not from share rows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">RowCause and Apex Sharing Reasons<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">RowCause stores why the share exists. Manual shares use the value Manual and disappear when the owner changes. Apex sharing reasons, such as Instructor__c, survive owner changes and let you find your own shares easily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating Sharing Reasons<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Apex sharing reasons exist only on custom objects. You create them in Salesforce Classic on the object&#8217;s detail page, in the Apex Sharing Reasons related list. Then you reference them as Schema.Course__Share.RowCause.Instructor__c.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Manual Sharing vs Apex Managed Sharing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares manual shares created by code with shares that use an Apex sharing reason.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>RowCause Manual<\/th><th>Apex sharing reason<\/th><\/tr><\/thead><tbody><tr><td>Created by<\/td><td>Users or code<\/td><td>Code only<\/td><\/tr><tr><td>Survives owner change<\/td><td>No, deleted<\/td><td>Yes<\/td><\/tr><tr><td>Objects<\/td><td>Standard and custom<\/td><td>Custom only<\/td><\/tr><tr><td>Easy to find later<\/td><td>Mixed with user shares<\/td><td>Filter by RowCause<\/td><\/tr><tr><td>Best for<\/td><td>One-off user shares<\/td><td>Rules driven by data<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is clear. Use an Apex sharing reason for every rule your code owns. Leave Manual row causes to users who click the Sharing button.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-2-1024x640.png\" alt=\"Apex Managed Sharing diagram comparing Manual row cause and an Apex sharing reason\" class=\"wp-image-1595\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Manual RowCause vs Apex sharing reason.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Course__Share Fields<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the values our code sets.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Field<\/th><th>Value in our example<\/th><\/tr><\/thead><tbody><tr><td>ParentId<\/td><td>The Course__c Id<\/td><\/tr><tr><td>UserOrGroupId<\/td><td>The Instructor__c user Id<\/td><\/tr><tr><td>AccessLevel<\/td><td>Edit<\/td><\/tr><tr><td>RowCause<\/td><td>Schema.Course__Share.RowCause.Instructor__c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Apex Managed Sharing Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s build Apex Managed Sharing for instructors at Bright Path Tutors. Course__c has a Private org-wide default and an Instructor__c lookup to User.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Sharing Service<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public without sharing class CourseSharingService {\n\n    public static void shareWithInstructors(List&lt;Course__c&gt; courses) {\n        Set&lt;Id&gt; courseIds = new Map&lt;Id, Course__c&gt;(courses).keySet();\n\n        \/\/ Remove old instructor shares for these courses\n        delete [SELECT Id FROM Course__Share\n                WHERE ParentId IN :courseIds\n                AND RowCause = :Schema.Course__Share.RowCause.Instructor__c\n                WITH SYSTEM_MODE];\n\n        List&lt;Course__Share&gt; shares = new List&lt;Course__Share&gt;();\n        for (Course__c c : courses) {\n            if (c.Instructor__c != null &amp;&amp; c.Instructor__c != c.OwnerId) {\n                shares.add(new Course__Share(\n                    ParentId = c.Id,\n                    UserOrGroupId = c.Instructor__c,\n                    AccessLevel = 'Edit',\n                    RowCause = Schema.Course__Share.RowCause.Instructor__c));\n            }\n        }\n        Database.insert(shares, false, AccessLevel.SYSTEM_MODE);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The service deletes only shares with the Instructor reason, so manual shares stay. Then it builds one Edit share per course. It skips owners, because owners already have full access. Database.insert with allOrNone set to false keeps going if one user is inactive.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Call It from the Trigger Handler<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>when AFTER_INSERT {\n    CourseSharingService.shareWithInstructors((List&lt;Course__c&gt;) Trigger.new);\n}\nwhen AFTER_UPDATE {\n    List&lt;Course__c&gt; changed = new List&lt;Course__c&gt;();\n    for (Course__c c : (List&lt;Course__c&gt;) Trigger.new) {\n        if (c.Instructor__c != ((Course__c) Trigger.oldMap.get(c.Id)).Instructor__c) {\n            changed.add(c);\n        }\n    }\n    if (!changed.isEmpty()) { CourseSharingService.shareWithInstructors(changed); }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Shares need a record Id, so this runs in after triggers. On update, only courses whose instructor changed are processed. That keeps the logic bulk-safe and cheap.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Check the Shares<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a query result after Rahul is set as the instructor of Apex Basics.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ParentId            UserOrGroupId   AccessLevel  RowCause\na015g00000AbC12AAB  005...Rahul     Edit         Instructor__c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The record&#8217;s sharing page now shows Rahul with Edit access and the reason Instructor. When the course owner changes, the share stays.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex Managed Sharing Recalculation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If sharing rules or data change a lot, shares can drift. So you can register a Batch Apex class as the object&#8217;s Apex sharing recalculation class. Admins then click Recalculate to rebuild every Apex share. We cover Batch Apex in Level 7.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Apex Managed Sharing<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using RowCause Manual, so shares vanish when the owner changes.<\/li>\n\n<li>Trying to share records whose org-wide default is Public Read\/Write.<\/li>\n\n<li>Deleting all share rows instead of only your own reason.<\/li>\n\n<li>Inserting shares in before triggers, where the record has no Id.<\/li>\n\n<li>Letting one inactive user fail the whole insert.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Apex Managed Sharing<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create one Apex sharing reason per business rule.<\/li>\n\n<li>Keep sharing logic in one service class with a clear name.<\/li>\n\n<li>Delete and recreate shares only for records whose key field changed.<\/li>\n\n<li>Use Database.insert with allOrNone false and log failures.<\/li>\n\n<li>Provide a recalculation batch for large data changes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add a second sharing reason called Coordinator. Then share each course with a public group named Course Coordinators with Read access. Hint: UserOrGroupId accepts a group Id, which you can query from the Group object by DeveloperName.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on Apex Managed Sharing<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Sharing in code is a favourite senior-level topic. Here are the 21 questions asked most about Apex Managed Sharing.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on Apex Managed Sharing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is Apex managed sharing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sharing records through Apex by inserting share object rows with an Apex sharing reason.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What is the share object for Course__c?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Course__Share.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: What fields does a custom share row need?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ParentId, UserOrGroupId, AccessLevel and RowCause.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Which access levels can Apex shares grant?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Read or Edit.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: What is RowCause?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The reason the share exists, such as Manual or a custom Apex sharing reason.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: Where do you create Apex sharing reasons?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the custom object&#8217;s detail page in Salesforce Classic, in the Apex Sharing Reasons related list.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: Do standard objects support Apex sharing reasons?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Standard objects can only use Manual and other built-in reasons.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on Apex Managed Sharing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: What happens to Manual shares when the owner changes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce deletes them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: What happens to shares with an Apex sharing reason when the owner changes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They remain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: Why run sharing code in an after trigger?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because share rows need the record Id, which exists only after the save.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you reference a sharing reason in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use Schema.Course__Share.RowCause.Instructor__c.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Can you share with a public group?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. Put the group Id in UserOrGroupId.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Why use Database.insert with allOrNone false for shares?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So one bad row, such as an inactive user, does not stop the other shares.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: Can you create shares when the OWD is Public Read\/Write?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No. Share rows only make sense when the OWD is more restrictive than the access you grant.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on Apex Managed Sharing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: What is an Apex sharing recalculation class?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Batch Apex class registered on the object that rebuilds Apex shares when an admin clicks Recalculate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: How do you update shares when the instructor changes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Delete shares with that reason for the record, then insert new ones for the new instructor.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Should sharing code run in user or system mode?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually system mode in a small without sharing service, because users often cannot create shares themselves.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How do you avoid sharing with the owner?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Skip rows where the target user is already the owner, since owners have full access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: How do Apex shares affect performance?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Many share rows add to sharing calculations, so share with groups where possible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you test Apex managed sharing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Insert records in a test, query the share object for your RowCause, and check access with System.runAs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: When should you use a sharing rule instead?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the rule depends on owner, role, group or simple field criteria that sharing rules support.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/apex-dev\/references\/apex-dev\/apex-bulk-sharing.html\" target=\"_blank\" rel=\"noopener noreferrer\">Understanding Apex Managed Sharing (Apex Developer Guide)<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_bulk_sharing_creating_with_apex.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Sharing a Record Using Apex (Apex Developer Guide)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apex Managed Sharing shares records by inserting share object rows.<\/li>\n\n<li>Each row sets ParentId, UserOrGroupId, AccessLevel and RowCause.<\/li>\n\n<li>Apex sharing reasons survive owner changes, while Manual shares do not.<\/li>\n\n<li>Run sharing code in after triggers and only for changed records.<\/li>\n\n<li>A recalculation batch can rebuild shares after big changes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Secure data access also means secure input and output. Next, read our guide to <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-secure-coding-xss-csrf-injection\/\">Apex secure coding against XSS, CSRF and injection<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apex Managed Sharing lets your code give a user or group access to a record when sharing rules cannot express the rule. For example,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1593,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[68,98,91,7,97,17,77],"swapz_series":[],"class_list":["post-1596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-advanced","tag-apex","tag-interview-questions","tag-salesforce","tag-salesforce-developer","tag-security","tag-sharing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Apex Managed Sharing: Share Records with Code<\/title>\n<meta name=\"description\" content=\"Apex Managed Sharing explained simply: share objects, RowCause, Apex sharing reasons, access levels, owner changes, recalculation and 21 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apex Managed Sharing: Share Records with Code\" \/>\n<meta property=\"og:description\" content=\"Apex Managed Sharing explained simply: share objects, RowCause, Apex sharing reasons, access levels, owner changes, recalculation and 21 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-09T07:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Apex Managed Sharing: Share Records with Code\",\"datePublished\":\"2026-09-09T07:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/\"},\"wordCount\":1611,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-managed-sharing-share-records-featured.png\",\"keywords\":[\"Advanced\",\"Apex\",\"Interview Questions\",\"Salesforce\",\"Salesforce Developer\",\"Security\",\"Sharing\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/\",\"name\":\"Apex Managed Sharing: Share Records with Code\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-managed-sharing-share-records-featured.png\",\"datePublished\":\"2026-09-09T07:30:00+00:00\",\"description\":\"Apex Managed Sharing explained simply: share objects, RowCause, Apex sharing reasons, access levels, owner changes, recalculation and 21 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-managed-sharing-share-records-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/apex-managed-sharing-share-records-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Apex Managed Sharing featured image: title card with an Apex code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/apex-managed-sharing-share-records\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apex Managed Sharing: Share Records with Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apex Managed Sharing: Share Records with Code","description":"Apex Managed Sharing explained simply: share objects, RowCause, Apex sharing reasons, access levels, owner changes, recalculation and 21 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/","og_locale":"en_US","og_type":"article","og_title":"Apex Managed Sharing: Share Records with Code","og_description":"Apex Managed Sharing explained simply: share objects, RowCause, Apex sharing reasons, access levels, owner changes, recalculation and 21 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-09T07:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Apex Managed Sharing: Share Records with Code","datePublished":"2026-09-09T07:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/"},"wordCount":1611,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-featured.png","keywords":["Advanced","Apex","Interview Questions","Salesforce","Salesforce Developer","Security","Sharing"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/","url":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/","name":"Apex Managed Sharing: Share Records with Code","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-featured.png","datePublished":"2026-09-09T07:30:00+00:00","description":"Apex Managed Sharing explained simply: share objects, RowCause, Apex sharing reasons, access levels, owner changes, recalculation and 21 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/apex-managed-sharing-share-records-featured.png","width":2400,"height":1260,"caption":"Apex Managed Sharing featured image: title card with an Apex code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/apex-managed-sharing-share-records\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Apex Managed Sharing: Share Records with Code"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1596"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1596\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1593"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1596"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}