Delete failed. first error: INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id: []
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
That's CustomSharedUtil.obtainOrderRequestShareToDrop:
public static List
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.
It's probably a hierarchy issue, as already mentioned. However, to actually delete the share will take a little trickery.
The answer is to use a webservice. Here is an example:
global class ObjectUtilWebservice { webservice static Boolean deleteObjects(String[] ids, String objectType) { String query = 'SELECT Id FROM ' + objectType + ' WHERE Id IN :ids '; try { SObject[] objects = Database.query(query); delete objects; return true; } catch (Exception e) { return false; } } }
This object takes a list of Ids and an object type and will delete anything you pass it.
Eg: String[] ids = new String[]{'a0429000003G1OdAAK'}; ObjectUtilWebservice.deleteObjects(ids, 'YourSobjectName');
Now all you need to do is modify your original call to return a list of ids rather than objects and pass it to the web services to handle.
Note: There are no limits to checking here or any check to ensure that the caller has permission to delete these objects, so use carefully.