Activity Forums Salesforce® Discussions Define managed sharing in APEX?

  • chanchal kumar

    Member
    September 5, 2018 at 2:39 pm

    Hello Prachi,

    This is a capability that allows Salesforce developers and admins to share the resources. Specific permissions are set to manage the sharing and limit the access. You are free to change the permissions whenever needed.

  • Avnish Yadav

    Member
    September 5, 2018 at 2:43 pm

    Hi Prachi,

    Apex managed sharing provides developers with the ability to support an application’s particular sharing requirements programmatically via Apex code.

    Thanks.

  • Parul

    Member
    September 5, 2018 at 10:07 pm

    Hi Prachi,

    To access sharing programmatically, you must use the share object associated with the standard or custom object for which you want to share. For example, AccountShare is the sharing object for the Account object, ContactShare is the sharing object for the Contact object. In addition, all custom object sharing objects are named as follows, where MyCustomObject is the name of the custom object:
    MyCustomObject__Share
    This is a capability that allows Salesforce developers and admins to share the resources. Specific permissions are set to manage the sharing and limit the access.

    Hope this helps.!!

  • shariq

    Member
    September 6, 2018 at 2:35 pm

    Hi Prachi,

    Sharing access granted by Force.com through record ownership, the role hierarchy, territory hierarchy, teams, and sharing rules:

    Record Ownership: Each record is owned by a user. The record owner is automatically granted Full Access, allowing them to view, edit, transfer, share, and delete the record. Role Hierarchy: The role hierarchy enables users above another user in the hierarchy to have the same level of access to records owned by or shared with users below them. Territory Hierarchy: Salesforce Territory Management provides a way to grant access to accounts based on characteristics of those accounts. The territory hierarchy enables users to view data shared to their territories or territories below them in the hierarchy.

    Teams: Account Teams, Sales Teams and Case Teams provide access to a group of users who work on a particular account, opportunity or case.

    Sharing Rules: Sharing rules are defined by administrators. They automatically grant users within a given group/role access to records owned by a specific group of users. Criteria based sharing rules automatically grant a users within a given group/role access to records based on field values within those records. User Managed Sharing, also known as Manual Sharing User managed sharing allows the record owner, or any user with Full Access to a record, to share the record with another user/group of users. This is generally done by an end-user, for a single record. User managed sharing is removed when the record owner changes or when the access granted in the sharing does not grant additional access beyond the object's organization-wide sharing default access level.

    Apex Managed Sharing

    Apex managed sharing is a type of "Programatic Sharing" which allows you to define a custom sharing reason to associate with your programatic share. Standard Salesforce objects support "Programatic Sharing" while custom objects support Apex managed sharing. More specifically, object shares can be written to both standard and custom objects, however custom sharing reasons can only be defined for shares written to custom objects.

    Apex managed sharing provides developers with the ability to support an application’s particular sharing requirements programmatically via Apex code.

    The sample use case for Apex managed sharing that we will explore in this article is an "after insert" trigger that grants 'edit' access on a private record to a user specified in a lookup field on that record.

    Another example use case would be a trigger that shares a record with a group of users once the record meets certain criteria - you could automatically grant 'read' access on a record to a team once the record reaches a certain stage or currency amount. You're not limited to writing triggers though-you can also use Apex managed sharing in custom Visualforce controllers for example. Now let's dive in and learn how records are shared on the platform.

    Hope this helps.

  • Anjali

    Member
    September 7, 2018 at 1:34 pm

    Hi Prachi,

    As we know, we have different ways of sharing a record in Salesforce. One of the ways is Apex Managed Sharing which is a bit adavanced compared to others and has to be builit programmatically through Apex or Soap API.

    Apex managed sharing provides developers with the ability to support an application’s particular sharing requirements programmatically through Apex or the SOAP API. This type of sharing is similar to Force.com managed sharing. Only users with “Modify All Data” permission can add or change Apex managed sharing on a record. Apex managed sharing is maintained across record owner changes.

    Basically, if you want to share a record programmatically we use Apex Managed Sharing.
    For example, AccountShare is the sharing object for the Account object, ContactShare is the sharing object for the Contact object, and so on. In addition, all custom object sharing objects are named as follows, where MyCustomObject is the name of the custom object:
    MyCustomObject__Share

Log In to reply.

Popular Salesforce Blogs