Record Sharing in Salesforce: Manual, Automated & Apex Sharing Explained

Record Sharing in Salesforce: Manual, Automated & Apex Sharing Explained 

Salesforce is all about data access control, ensuring that the right users see the right data at the right time. Whether you’re sharing records with a teammate or automating visibility to an entire department, Salesforce provides flexible and secure sharing mechanisms to get the job done. 

In this blog, we’ll dive into the three primary ways to share records in Salesforce: 

📌 Methods of Record Sharing 

  1. Manual Sharing (Using the Sharing Button) 
  1. Automated Sharing (Using Sharing Rules) 
  1. Apex Sharing (Via Apex Code) 

🧑💻 1. Manual Sharing – One Record at a Time 

Manual Sharing is perfect when you need to share an individual record with a specific user or group. 

When to Use: 

  • Quick ad-hoc record access 
  • Temporary collaboration 
  • Sharing sensitive records selectively 

⚙️ Prerequisite: 

The Organization-Wide Default (OWD) for the object must be set to Private. Only then will the “Sharing” button appear on record detail pages. 

🔧 Steps to Share a Record Manually 

Let’s say you’re logged in as a Development User and want to share an Account record with a Testing User (Read-Only access). 

  1. Go to the Accounts tab and open the target record 
  1. Click the “Sharing” button 
  1. Click “Add” 
  1. Select the user (e.g., Testing User) 
  1. Choose Access Level → Read Only 
  1. Click Save 

🔍 Observation: 

When the Testing User logs in, they can now view the record—but cannot edit or delete it. 

🔁 Sharing with Multiple Users? Use a Public Group! 

Manual sharing with many users can be repetitive. Instead, create a Public Group. 

📂 What is a Public Group? 

A Public Group is a named collection of users, roles, or other groups. Once created, it can be reused to share records to multiple users at once. 

🛠️ Steps to Create a Public Group 

  1. Go to Setup 
  1. Expand Manage Users → Click Public Groups 
  1. Click New Group 
  1. Name the group (e.g., Hyderabad Sales Group) 
  1. Add members: Users, Roles, or other Groups 
  1. Click Save 

🔎 Public Groups live in the Group object (ID starts with OOG), and their members are tracked in the GroupMember object. 

🤖 2. Automated Sharing – Using Sharing Rules 

Manually sharing each record is tedious. Salesforce solves this with Sharing Rules, which automate access to records based on certain conditions. 

Two Types of Sharing Rules: 

  1. Owner-Based Sharing Rules – Share records based on their owner 
  1. Criteria-Based Sharing Rules – Share records based on record field values 

🔍 Use Case: 

Create a Sharing Rule to grant Read-Only access to Account records for the Hyderabad Sales Group when: 

  • Rating = Hot 
  • Industry = Healthcare 
  • Active = Yes 
  • Ownership = Private 

⚙️ Steps to Implement Criteria-Based Sharing Rule 

  1. Go to Setup 
  1. Navigate to Security Controls → Click Sharing Settings 
  1. In the Sharing Rules section, click on the object (e.g., Account Sharing Rules) 
  1. Click New 
  1. Name the rule: Grant Account Access to Hyderabad Sales Group 
  1. Select Rule TypeBased on Criteria 
  1. Set the conditions: 
  • Rating = ‘Hot’ 
  • Industry = ‘Healthcare’ 
  • Active = ‘Yes’ 
  • Ownership = ‘Private’ 
  1. Define the users to share with: 
  • Choose Public Groups 
  • Select Hyderabad Sales Group 
  1. Choose the access level: Read Only or Read/Write 
  1. Click Save 

Once saved, the rule automatically grants access to any matching records—no manual steps required. 

🧩 3. Apex Sharing – Programmatic Flexibility 

When you need complex, dynamic, or highly customized sharing, you can use Apex code to create Apex Sharing Rules. 

This allows: 

  • Conditional logic beyond standard sharing rules 
  • Sharing in batch processes 
  • Revoking access based on business events 

(Note: We’ll cover Apex Sharing in detail in a future post!) 

🎯 Wrapping Up 

Choosing the right record sharing approach depends on your use case: 

Scenario  Best Method 
Share one-off records manually  Manual Sharing 
Share records based on logic (e.g., industry, region)  Sharing Rules 
Share using code or dynamic logic  Apex Sharing 

 

🔐 Salesforce Record Sharing – Best Practices (Quick Guide) 

  1. Start Restrictive – Set OWD to the most private setting, then open access as needed. 
  1. Limit Role Depth – Keep role hierarchy flat for better performance. 
  1. Go Declarative First – Use sharing rules before Apex sharing. 
  1. Group Wisely – Use Public Groups/Queues instead of individual users. 
  1. Minimize Ownership Changes – Reduces sharing recalculations. 
  1. Use Apex Sharing Sparingly – Only for complex, custom logic. 
  1. Avoid Manual Sharing – Hard to manage at scale. 
  1. Batch Recalculations – Don’t overuse recalculateSharingRules(). 
  1. Enable the Sharing Button – Helpful for debugging access issues. 
  1. Audit Regularly – Use logs and tools to monitor access. 

By understanding and using these three powerful sharing strategies in Salesforce, you’ll be able to tailor data visibility to match your organization’s structure—securely and efficiently. 

 

Leave a Comment

Your email address will not be published. Required fields are marked *