+ Start a Discussion
Tyler HarrisTyler Harris 


I've got a trigger that's throwing the following error:


shareBackCase: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: [] Trigger.shareBackCase: line 19, column 1

What I'm trying to do is when a case is assigned to a Queue I want the user to be able to access the case with "Read" access. I can't seem to get the Sharing Rule to insert. What do I need to do fix?
trigger shareBackCase on Case (after insert) {
	ID recordTypeId = [SELECT Id, Name FROM RecordType WHERE name ='Commissions' LIMIT 1].id;
    List <CaseShare> newCazeList = new List<CaseShare>();

    for(Case c:Trigger.new){
       CaseShare newCaze = new CaseShare();
        if(c.RecordTypeId == recordTypeId){
            newCaze.CaseId = c.Id;
            newCaze.UserOrGroupId = c.CreatedById;
        	newCaze.CaseAccessLevel = 'Read';
            newCaze.RowCause = 'Manual';

    insert newCazeList;

My org is a private sharing model.
srlawr uksrlawr uk
I think the problem here might be that you cannot insert a sharing rule that restricts the permissions of the user who owns a record. they always have to have full access to their records. You won't be able to use sharing rules to remove "edit" rights to a case whilst that users owns it, sorry!