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
P 186P 186 

Case Sharing Record

parent case sharing  record visible to partner account users though apex program.
Ajay K DubediAjay K Dubedi
Hi,

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, and so on. In addition, all custom object sharing objects are named as follows, where MyCustomObject is the name of the custom object: “MyCustomObject__Share”.

Go through below code:
 
trigger Test_Share on Test__c (after insert) {

 if(trigger.isInsert){

     List<Test_Share> jobShares = new List<Test_Share>();

     for(Test__c t : trigger.new){

         Test_Share studentRecord = new Test_Share();

         studentRecord.ParentId = t.Id;

         studentRecord.UserOrGroupId = t.student__c;

         studentRecord.AccessLevel = 'edit';
 
         studentRecord.RowCause = Schema.Test_Share.RowCause.Student_Access__c;

         jobShares.add(studentRecord);
     }

     Database.SaveResult[] jobShareInsertResult = Database.insert(jobShares,false);
     }
}

Also see this link it may helpful for you:
https://www.jitendrazaa.com/blog/salesforce/apex-based-sharing-in-salesforce/

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi