0

While doing after update trigger I am getting the insufficient error. Requirement: in my scenario, record x can b created by admin and manager. but auditor can create a y record from x. x and y are in a parent-child relationship. while saving record x, the parent owner id will be changed to rep. I am sharing the y record when updating status.This record needs to be shared to CreatedBy of X record.

public class USRetail_CRATriggerHandler {
    public static void shareCoachingReportAuditRec(List<ID> ids) 
    {
    List<Coaching_Report_Audit__Share> craList=new List<Coaching_Report_Audit__Share>();
    List<Coaching_Report_Audit__c> coachingreportaudits=[select id,Coaching_Report__r.createdByid from Coaching_Report_Audit__c where id=:ids];
    for(Coaching_Report_Audit__c cra:coachingreportaudits){
        Coaching_Report_Audit__Share crashare=new Coaching_Report_Audit__Share();
        crashare.ParentId=cra.Id;
        crashare.RowCause='Manual';
        crashare.UserOrGroupId=cra.Coaching_Report__r.createdByid;        
        crashare.AccessLevel='Edit';
        craList.add(crashare);
    }
    insert craList;
    //system.debug('Test------>'+craList);
}
}

Error

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY,: Class.USRetail_CRATriggerHandler.shareCoachingReportAuditRec: line 14

0

If your custom object is related to parent as Master Details relationship, you can not have a sharing object. It will be determined by the parent's sharing setting.

Or

If that user has already had a sharing access on that record, this error will be thrown. try using Database.SaveResult sr = Database.insert(crashare,false); to avoid the error on record saving.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.