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
trmptrmp 

Give Community User Access to Case he/she Created when Case is Reassigned Using Assignment Rules

We have a community where community users can open cases. We are inserting the case via Apex which changes the owner due to using the default case assignment rule:

Database.DMLOptions dmo = new Database.DMLOptions();
dmo.assignmentRuleHeader.useDefaultRule= true;
dmo.EmailHeader.triggerAutoResponseEmail = false;
caseRecord.setOptions(dmo);

insert caseRecord;
Without adding a CaseShare record, the community user will no longer be able to access the newly created case. However, when inserting the CaseShare record, we cannot get around this error:

Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []

Here's a snippet of adding the CaseShare record. We've tried this in the above class marked as "without sharing", in a future method from a trigger, with and without also adding an AccountShare record.

insert new CaseShare(
    CaseAccessLevel = 'Read',
    CaseId = c.Id,
    UserOrGroupId = c.CreatedById
);
Any help would be much appreciated.
Best Answer chosen by trmp

All Answers

trmptrmp
Apparently share records cannot be assigned to community users.
trmptrmp
This was selected as the best answer