I want to share cases created by community users with the community users(contacts) of the parent account of the associated account.Sharing sets are an all or nothing.
So I thought about apex sharing and started with writing a small snippet in developer console to test if it works for community users
CaseShare share = new CaseShare(); share.CaseId = '5005B000002giXf'; share.UserOrGroupId = '0055B000000vZ7W'; share.CaseAccessLevel = 'read'; insert share;
But this gave an error
Line: 5, Column: 1 System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: