+ Start a Discussion
Navneeth RajNavneeth Raj 

OpportunityShare Trigger ERROR

trigger instantTrigger on Opportunity (before insert,after update) {
    List<OpportunityShare> share=new List<OpportunityShare>();
    User u=[SELECT id FROM User WHERE alias='sara'];
    for(Opportunity op:Trigger.New){
        if(op.Type=='New Customer'){
            OpportunityShare so=new OpportunityShare();
            so.OpportunityId=op.id;
            so.OpportunityAccessLevel='Edit';
            so.UserOrGroupId=u.Id;
            so.RowCause='Manual';
            share.add(so);
        }
    }
    insert share;
}

Error:Apex trigger instantTrigger caused an unexpected exception, contact your administrator: instantTrigger: execution of AfterUpdate 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.instantTrigger: line 14, column 1
 
sfdc Beginnersfdc Beginner
Hi Navneeth,

There are a number of reasons why this error crops up


    If you are trying to share "Record A" with "User B" and you yourself do not have access to "Record A", this error happens.


    If you are trying to share "Record A" with "User B" and "User B" does not have access to the object

    (the profile level permission, create read   edit delete), this error happens.


    If you are trying to share "Record A" with "User B" and "Use B" already has access to "Record A" this error happens.


If this solves your Problem, Mark it as the Best Answer.



Thanks,
SFDC Beginner