We created a tool that scans Permission Sets of a installed managed package, "clones" these Permission Sets and removes any Permissions defined as too powerful.
However upon FieldPermissions Insert i get the following Error:
System.DmlException Insert failed. First exception on row 2803; first error: DUPLICATE_VALUE, duplicate value found: < unknown> duplicates value on record with id: < unknown>: [], 2018-07-18 11:56:41
consider the following piece of code:
// Used to create a new set or get an existing one
PermissionSet clone = fetchCloneSet();
if(clone.Id == null) {
insert clone;
}
// Get New Permissions to be granted
List<ObjectPermissions> objectPermissions = fetchObjectPerms();
List<FieldPermissions> fieldPermissions = fetchFieldPerms();
List<SetupEntityAccess> setupEntityAccessItems = fetchSetupEntityPerms();
// Delete existing Permissions
delete [SELECT Id FROM SetupEntityAccess WHERE ParentId = :clone.Id];
delete [SELECT Id FROM FieldPermissions WHERE ParentId = :clone.Id];
delete [SELECT Id FROM ObjectPermissions WHERE ParentId = :clone.Id];
// Insert new Permissions
insert objectPermissions;
insert fieldPermissions;
insert setupEntityAccessItems;
The Error occurs upon FieldPermissions insert. I know that because the Permission Set causing the error should get less than 1000 Object- and SetupEntity Permissions but over 2800 FieldPermissions.
After some Investigation I found some articles about the topic in this StackExchange Question. Seems Like there are DML errors and Deployment Errors with this message. However the DML Errors seem to be connected to a Custom Field set to "Unique" and FieldPermissions does not have a unique field according to the schema.
Any ideas what this very unhelpful error message is about?
FieldPermissions
object onParentId
,SObjectType
, andField
fields. Is there something infetchFieldPerms
that's creating a duplicate of those three fields?