Scenario: A 'Customer Community' License user logs into a community and creates a case, which is automatically assigned to a queue. A trigger on case invokes a future method (of a class declared without sharing) to recalc sharing by identifying 'Customer Community Plus' user(s) who should have access to the case. The future method queries for existing CaseShare records, deletes any which no longer apply, and adds any which do not apply. This is consistently failing when inserting CaseShare records with:

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

I have confirmed via debug logs the following (for a given test case):

  1. The code is identifying 2 users who need new CaseShare records.
  2. No CaseShare records exist prior to the attempted insert.
  3. Both users have licence 'Customer Community Plus'.
  4. Both users have the same Profile, and that profile includes Read, Create, and Edit on Case, and has access to the Case Record Type in question.
  5. Neither user belongs to the queue that owns the case.
  6. When logged into the org as a SysAdmin, I can view the case and manually share the case to both users.

I've run out of things to check. I should be able to share this case with Customer Community Plus users via Apex Sharing, and I've checked everything else I can think of. What am I missing?

  • Even though I don't think that should necessarily have an impact here, but is the Apex class added to the Community Users Profiles? – Jayant Das Apr 17 at 20:13
  • Typically, Apex Managed Sharing needs to run in either a Schedulable, Queuable or Batch class. I would not try to run it in an @Future method from a trigger. I've yet to see that pattern work. When called from a trigger, those records are typically written to a temp object, then a trigger fires to call either a Queuable, Batch or Schedulable class that queries them and then does the sharing. – crmprogdev Apr 17 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.