In order to get the PermissionSetAssigment object I execute the following query which return one object and that same object is added to the listPermissionSetsUnlockUser
List<PermissionSetAssignment> listPermissionSetsUnlockUser =[SELECT Id, AssigneeId, PermissionSetId FROM PermissionSetAssignment WHERE AssigneeId = :userIdToPressUnlock AND PermissionSetId = :oppPsId AND PermissionSetId IN (SELECT Id FROM PermissionSet WHERE IsOwnedByProfile = false)];
for(PermissionSetAssignment psaListUnlockUser :listPermissionSetsUnlockUser){
System.debug('psaListUnlockUser ' + psaListUnlockUser);
}
integer listSizeUnlockUser = listPermissionSetsUnlockUser.size();
System.debug('listSizeUnlockUser ' + listSizeUnlockUser);
delete listPermissionSetsUnlockUser;
In the debug log file the list size is 1.
10:54:05.33 (48751170)|USER_DEBUG|[148]|DEBUG|listSizeUnlockUser 1
but I receive the following error:
FATAL_ERROR|System.DmlException: Delete failed. First exception on row 0 with id 0Pa7E000001ufFlSAI; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []
Could you please explain why I receive such error for an object which already exist in the PermissionSetAssigment table?
Still get the same error INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [] even though the query is successfully executed.
Can anyone advise appropriate solution and how to get rid of such error because this it is really urgent and critical to find a way out of this issue.