Activity › Forums › Salesforce® Discussions › How to create share table record using apex in Salesforce?
-
How to create share table record using apex in Salesforce?
Posted by Anjali on August 31, 2018 at 12:47 PMHow to create share table record using apex in Salesforce?
Parul replied 7 years, 7 months ago 3 Members · 2 Replies -
2 Replies
-
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.
- [adinserter block='9']
-
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.