Activity Forums Salesforce® Discussions How to create share table record using apex in Salesforce?

  • Avnish Yadav

    Member
    August 31, 2018 at 12:54 pm

    Hi Anjali,

    Share table contains four columns: ParentId, UserOrGroupId, RowCause, AccessLevel.
    Below is code to create position__share record:
    Position__share p = new Position__share();
    p.parentId = ‘Position Record Id which needs to be shared’;
    p.userOrGroupId= ‘User id or Group id with which we want to share record’;
    p.RowCause=’ apex sharing reason defined for a custom object, here for position__c’;
    p.AccessLevel =’access level for the record’; //can be Read or Edit
    insert p;

    Note: you cannot update share table record. The system only allows insert or delete of records for the share table. So if you have to change access for the user, you have created a new record and can delete an already existing record if you want.

    Hope this will help you.

    Thanks.

  • Parul

    Member
    September 24, 2018 at 12:09 am

    A custom object’s share object allows four pieces of information to be defined:
    The record being shared.
    The User or Group with whom the object is being shared.
    The permission level being granted to the User or Group.
    The reason why the User or Group has been granted sharing access.

Log In to reply.

Popular Salesforce Blogs

Steps to Connect Pardot to Salesforce

Steps to Connect Pardot to Salesforce

Blog in

Steps to Integrate Salesforce and Pardot: There are some steps to install Pardot in salesforce 1- Click on this link https://login.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t1W000000U7P8(production) https://test.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t1W000000U7P8 (sandbox) 2- After…

Popular Salesforce Videos