Activity Forums Salesforce® Discussions Is it possible to grant delete permission using apex managed sharing?

  • Is it possible to grant delete permission using apex managed sharing?

    Posted by Danna on April 20, 2016 at 9:57 am

    I have Custom_Object__c with:

    Org-Wide Default Settings as: Private
    Object Permissions in the user Profile: Create, Read, Edit, Delete.
    I have a small development in Apex that is creating some apex managed sharing rules, to give certain users access to records they don't own. So far I only needed to give the users either "Read" or "Edit" permissions. So all worked ok.

    However, now I need to grant users delete permissions for records they don't own. Without touching profile nor org-wide default settings. This would mean creating the apex managed sharing rules with accessLevel = 'All'.

    I looked into the documentation, it seems to say that it's not possible to do that.

    Shweta replied 3 years, 5 months ago 4 Members · 3 Replies
  • 3 Replies
  • Himanshu

    Member
    April 25, 2016 at 12:58 pm
  • Gourav

    Member
    April 26, 2016 at 10:48 am

    Hi Dana,

    Try this code block to grant 'All' permission to user using apex

    ObjectName__Share instance = new ObjectName__Share();
    instance.ParentId = Object.id;
    instance.UserOrGroupId = User/Group.id;
    instance.AccessLevel = 'All';
    instance.RowCause = Schema.ObjectName__Share.RowCause.Manual;

    Insert/update instance;

     

    Hope above helps you.

  • Shweta

    Member
    October 16, 2020 at 2:27 pm

    We cannot grant transfer, delete, or share permissions with Sharing rules but an all-access level can only be used by Force.com managed sharing.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos