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.