0

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.

3
  • It looks like the user who is executing the DML doesnt have the correct permissions for deletion of certain PermissionSetAssignment objects. – TSmith Nov 11 '16 at 20:05
  • I've tried with user with System Administrator profile who is having all permissions including the deletion of the PermissionSetAssignment object and still get the same error. Could you please advise how to get rid of such error? – digital mindfield Nov 11 '16 at 20:47
  • Actually the delete is performed successfully and after that I receive the error. Do you have any idea why I receive such error Delete failed... although the query is successfully executed? – digital mindfield Nov 11 '16 at 22:00
3

Please verify that the executing user has full security rights (including delete) on PermissionSetAssignment, PermissionSet, and User.

You also might want to make sure that the permission set this record is related to is not associated with a profile - an error we have seen is:

INVALID_CROSS_REFERENCE_KEY, You can't assign or unassign this permission set because it's associated with a profile.: []
2
  • Actually the delete is performed successfully and after that I receive the error. Do you have any idea why I receive such error Delete failed... although the query is successfully executed? – digital mindfield Nov 11 '16 at 22:00
  • I still get the same error INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: [] even though the query is successfully executed. Can you advise appropriate solution and how to get rid of such error. – digital mindfield Nov 12 '16 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.