I am trying to delete a share on a custom field, using a profile that doesn't have permissions for it.
field: Order_Request__C
And getting the following error:
System.DmlException: Delete[] failed. First exception on row 0 with id 02c5E00001RXlyMQAT; first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []
That's the function that deletes the sharing:
private void removeOrderRequestShare(Map> orderRequestIdToUsersSetMap, String accsessLevel) { List sharedToDropList = new List(); sharedToDropList = CustomSharedUtil.obtainOrderRequestShareToDrop(orderRequestIdToUsersSetMap, accsessLevel); delete sharedToDropList; }
That's CustomSharedUtil.obtainOrderRequestShareToDrop:
public static List obtainOrderRequestShareToDrop(Map> orderRequestIdToUsersSetMap, String accsessLevel) { List sharedToDropList = new List(); Set usersIdSet = new Set(); for (Id orderRequestId_i : orderRequestIdToUsersSetMap.keySet()) { usersIdSet.addAll(orderRequestIdToUsersSetMap.get(orderRequestId_i)); } List tmpSharedList = [SELECT Id, ParentId, UserOrGroupId FROM Order_Request__Share WHERE ParentId IN: orderRequestIdToUsersSetMap.keySet() AND UserOrGroupId IN: usersIdSet AND AccessLevel =: accsessLevel]; if (!tmpSharedList.isEmpty()) { for (Order_Request__Share share_i : tmpSharedList) { if (orderRequestIdToUsersSetMap.containsKey(share_i.ParentId) && orderRequestIdToUsersSetMap.get(share_i.ParentId).contains(share_i.UserOrGroupId)) { sharedToDropList.add(share_i); } } } System.debug('sharedToDropList: ' + sharedToDropList); return sharedToDropList; }
to fix it, i tried to add "without sharing" to the class, but it didnt work. This didn't work. i looked all over and ran out of ideas, please help. How to fix this delete[] failed issue.