Why have database rows not been inserted when the debug log says they have?

One of your share entries is failing to insert, causing the entire DML to go through the exception handler. Odds are, you're trying to insert a share for the case owner, which isn't allowed. Here's the POC I wrote that demonstrates this:

trigger Cases on Case (after insert, after update) {
    User testUser = [SELECT Id FROM User WHERE Name = 'test user'];
    CaseShare[] shares = new CaseShare[0];
    for(Case record: Trigger.new) {
        shares.add(new CaseShare(CaseId=record.id, UserOrGroupId=testUser.Id, CaseAccessLevel='edit'));
    }
    insert shares;
}

Throw this code into a developer edition or spare sandbox, and make sure you have a single user that is named 'Test User' (first name Test, last name User), and try to change the owner to this user, and you'll come across a rather <sarcasm>specific</sarcasm> exception:

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

If you try manually assigning a share to the case owner, you get the usual, friendly error message:

Error: Cannot manually share to the record owner.

Personally, I'd go with simply allowing any partial update to succeed instead of using the harsh all-or-none mechanism:

Database.insert(csShareList, false);

Duplicate shares are acceptable, as insert operations on share records are actually automatically upserts instead (they update a matching existing row when possible).


When a queue owns a case record in SF and the sharing model for the case is private

Only queue members and their direct reports can view or take ownership of [those] cases.

Page 21 Case Management Implementation Guide

Here are two exceptions I learned about from this experience.

  1. Other users can view the case if they have 'view all' on the object level or are in role hierarchy above someone with 'view all.'
  2. The calculation for this specific sharing event happens when you change or initially set the owner to a queue but will not be calculated in for updates to the record that do not change the ownership from a user to a queue, or from one queue to another. For example, if you set the owner to a queue and simultaneously try to share it with users that are not queue members, direct reporters of queue members, or users with 'view all' permission, the sharing will fail. However, if you set the owner to a queue, and in a separate transaction share the record with users that are not queue members or direct reporters of queue members, your sharing will succeed.

EDIT:

The reason for the failure of inserts was confirmed by Salesforce support.