function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
clouduserclouduser 

edit access to the record thru apex trigger (after update and after insert)

Need some assistance on apex sharing trigger for after update and after insert. Need to provide the edit access to the respective backup user (Backup_person__c field). It is on the custom object.

 

appreciate your help.

Best Answer chosen by Admin (Salesforce Developers) 
mohimohi

Customobject__Share jobShr = new Customobject__Share();

// Set the ID of record being shared.

jobShr.ParentId = recordId;//record id

// Set the ID of user or group being granted access.

jobShr.UserOrGroupId = userOrGroupId;// back up user Id

// Set the access level.

jobShr.AccessLevel = 'Edit';

// Set rowCause to 'manual' for manual sharing.

// This line can be omitted as 'manual' is the default value for sharing objects.

jobShr.RowCause = Schema.Customobject__Share.RowCause.Manual;

// Insert the sharing record and capture the save result.

// The false parameter allows for partial processing if multiple records passed

// into the operation.

Database.SaveResult sr = Database.insert(jobShr,false);

 

 

 

if Handling Bulk use : list

 

 

list<customobject__Share>  lst=new list<customobject__Share>();

lst.add(jobshare1);

Insert lst;

IF this is answer to your question please mark as accepted.