Activity Forums Salesforce® Discussions How to determine if a CustomObject__c record has been manually shared with the curren

  • How to determine if a CustomObject__c record has been manually shared with the curren

    Posted by shradha jain on September 3, 2018 at 1:06 pm

    How to determine if a CustomObject__c record has been manually shared with the current user in Apex?

    shariq replied 5 years, 8 months ago 3 Members · 2 Replies
  • 2 Replies
  • Parul

    Member
    September 3, 2018 at 1:11 pm

    Hello Shradha,

    By querying CustomObject__share we can manually shared with the current user in Apex.

     

    Thanks.

  • shariq

    Member
    September 15, 2018 at 1:12 am

    Hi,

    Firstly you should know about sharing record using apex -

    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

    Objects on the detail side of a master-detail relationship do not have an associated sharing object. The detail record’s access is determined by the master’s sharing object and the relationship’s sharing setting. For more information, see “Custom Object Security” in the Salesforce online help.

    A share object includes records supporting all three types of sharing: managed sharing, user managed sharing, and Apex managed sharing. Sharing granted to users implicitly through organization-wide defaults, the role hierarchy, and permissions such as the “View All” and “Modify All” permissions for the given object, “View All Data,” and “Modify All Data” are not tracked with this object.

    And the answer for your question is -

    A. By querying CustomObject__share
    B. By querying the role hierarchy.
    C. By calling the isShared() method for the record
    D. By calling the profile settings of the current user

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos