2

I have been battling with this for few days now. Below is my scenario.
I do have a trigger on Sampling__c object that updates the owner and assigns a manager for the request created. When updating the bu manager, I am receiving the following error :INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY
Below is the line that I am trying to update from debug log.

15:16:427.410 (2410228087)|USER_DEBUG|[136]|DEBUG|CodeDebugging:: lstSampleUpdate = (Sampling__c:{Id=a0cc0000006UnrhAAC, BU_manager__c=005E0000000ReHdIAK, BU_manager1__c=005E0000001dtsCIAQ, BU_manager2__c=005E0000000ReHdIAK, BU_manager3__c=005E0000000ReHdIAK, BU_manager4__c=005E0000000ReHdIAK})
15:16:427.410 (2410233311)|SYSTEM_METHOD_EXIT|[136]|System.debug(ANY)
15:16:427.410 (2410281089)|DML_BEGIN|[137]|Op:Update|Type:Sampling__c|Rows:1 15:16:427.433 (2433914293)|DML_END|[137]
15:16:427.434 (2434036718)|EXCEPTION_THROWN|[137]|System.DmlException: Update failed. First exception on row 0 with id a0cc0000006UnrhAAC; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
15:16:427.438 (2438620518)|SYSTEM_METHOD_ENTRY|[141]|String.valueOf(Object)
15:16:427.438 (2438657509)|SYSTEM_METHOD_EXIT|[141]|String.valueOf(Object)
15:16:427.438 (2438679644)|SYSTEM_METHOD_ENTRY|[141]|System.debug(ANY)
15:16:427.438 (2438689496)|USER_DEBUG|[141]|DEBUG|Exception : Not able to update the BU Manager System.DmlException: Update failed. First exception on row 0 with id a0cc0000006UnrhAAC; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []
15:16:427.438 (2438696016)|SYSTEM_METHOD_EXIT|[141]|System.debug(ANY)


    public static void populateBUManagerOnSample(List<Sampling__c>sampling)
{
//After insert Trigger
List<Business_Unit_Managers__c> lstBUMgrs=[Select b.Product_Line__c ,b.Product_Family__c,b.Object_Type__c, b.Item_Accounting_Class__c, b.Id, b.Business_Unit__c, b.BU_Manager__c, b.BU_Manager1__c, b.BU_Manager2__c, b.BU_Manager3__c, b.BU_Manager4__c From Business_Unit_Managers__c b where b.Object_Type__c='Sample'];

System.Debug('CodeDebugging::');
Map<String, > MapBUMgrs = new Map<String,Business_Unit_Managers__c>();
List<Sampling__c > lstSampleUpdate=new List<Sampling__c >();

for(Business_Unit_Managers__c bu:lstBUMgrs) {
MapBUMgrs.put(bu.Item_Accounting_Class__c + bu.Product_Line__c + bu.Product_Family__c ,bu);
System.Debug('CodeDebugging:: Map BU ' + bu.Item_Accounting_Class__c  + ' == ' + bu.Product_Line__c + ' == ' + bu.Product_Family__c);
  }

 if(Trigger.isAfter){
 for(Sampling__c sp: sampling){  
 id tempUser;
 Sampling__c s = new Sampling__c (id=sp.id); 
 System.Debug('CodeDebugging:: Compare=' + sp.Business_Unit__c + ' == ' + sp.Product_Line__c + ' == ' + sp.Product_Family__c);

if(MapBUMgrs.containsKey(sp.Business_Unit__c+ sp.Product_Line__c + sp.Product_Family__c )){
Business_Unit_Managers__c temps = MapBUMgrs.get(sp.Business_Unit__c+ sp.Product_Line__c + sp.Product_Family__c);
System.Debug('CodeDebugging:: Inside BU');
System.Debug('CodeDebugging:: BU manager' + temps.BU_Manager__c);
                                if(temps.BU_Manager__c!=null)
                                tempUser = temps.BU_Manager__c;
                                else if(temps.BU_Manager1__c!=null)
                                tempUser=temps.BU_Manager__c;
                                else if(temps.BU_Manager2__c!=null)
                                tempUser=temps.BU_Manager__c;
                                else if(temps.BU_Manager3__c!=null)
                                tempUser=temps.BU_Manager__c;
                                else if(temps.BU_Manager4__c!=null)
                                tempUser=temps.BU_Manager__c;
                                s.BU_Manager__c  =(temps.BU_Manager__c!=null  ? temps.BU_Manager__c :tempUser);
                                s.BU_Manager1__c =(temps.BU_Manager1__c!=null ? temps.BU_Manager1__c :tempUser);
                                s.BU_Manager2__c =(temps.BU_Manager2__c!=null ? temps.BU_Manager2__c :tempUser);
                                s.BU_Manager3__c =(temps.BU_Manager3__c!=null ? temps.BU_Manager3__c :tempUser);
                                s.BU_Manager4__c =(temps.BU_Manager4__c!=null ? temps.BU_Manager4__c :tempUser);
                                System.Debug('CodeDebugging:: UpdateSample = ' + s);
                                lstSampleUpdate.add(s);
                            }
                        }
                    }
                    try{
                        System.Debug('CodeDebugging:: lstSampleUpdate = ' + lstSampleUpdate);
                        update lstSampleUpdate;
                        System.Debug('Product Line! ' + lstSampleUpdate);
                    }
                    catch(Exception e){
                        System.Debug('Exception : Not able to update the BU Manager ' + e);
                    }
                }

I checked the permission for the new user assigned and the request creator and they both have create/edit/read permission on the object. I checked the Sampling__Share object and there is an entry for the new record created too.
Any idea what else to search for? Any input greatly appreciated.

14
  • Does this object have a record type ? Business_Unit_Managers__c, also read this post ; forcetree.com/2011/12/… and see if there is a relevant scenario for your case
    – Rao
    Jun 11, 2015 at 18:46
  • Hi Rao, I did test these scenario's already and don't see anything related to that.
    – Gops
    Jun 11, 2015 at 18:52
  • are you getting this exception on certain users or on all the users at random inervals? Can you login as one of the user and see if the can access this specific 'a0cc0000006UnrhAAC' record of the Sampling__c object.
    – Rao
    Jun 11, 2015 at 18:56
  • You may want to execute this functionality after giving Modify All" rights to the concerned user, just to make sure some profile/FLS issues . Jun 11, 2015 at 18:56
  • I am not getting this error for all the user. Just for some external users who try to create the request. After creating, the request, when the apex class tries to update the manager field, this error happens. When I try to access the 'a0cc0000006UnrhAAC' as the user who creates it, they are able to see the record. But they do not have edit previlage. Maybe this might be the issue. How can I resolve it.
    – Gops
    Jun 11, 2015 at 21:00

1 Answer 1

0

insufficient access rights on cross-reference id mean that some of the field of your a0cc0000006UnrhAAC record is out of your authorization check the field(s), especially the filed that look up to the others records if you have access or not.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .