Apex based sharing a record with a User or Public Group is easy and direct. Below is the sample sharing of an Account record with a user. AccountShare Acctshr = new AccountShare(); Acctshr.AccountId = aid; Acctshr.UserOrGroupId = 'User.Id'; Acctshr.AccountAccessLevel = 'Edit'; Acctshr.OpportunityAccessLevel = 'Edit'; Database.SaveResult sr = Database.insert(Acctshr,false); But how do you share with a …