function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
CrowdcastCrowdcast 

You can't assign or unassign this permission set because it's associated with a profile.

I was previously able to delete PermissionSetAssignment through the REST API. Now I am getting:

 

You can't assign or unassign this permission set because it's associated with a profile.

 

I would think that I was doing exactly that - deleting the assignment to dissociate the profile from the PermissionSet. Any pointers? 

 

thanks

yan at crowdcast dot com

Andy BoettcherAndy Boettcher

You're going to have to navigate the PermissionSetAssignment object and remove all references to your target Permission Set before deleting.  The delete does not cascade.

 

-Andy

Hong_YanHong_Yan

This is a pretty old post, but I was searching for a resolution to the exact same error but couldn't find it anywhere, so I figured I'd put in what I found.

 

I was getting the exact same error though I was using apex instead of the rest api. Good chance it's the same issue though.

 

I was querying for all permissionsetassignments on a user record and attempting to delete the ones that didn't match.

There was one permissionsetassignment that was associated with a system generated permissionset rather than one of the ones I created. Since that one never matched any of the ones that I created, my code attempted to delete it. It was when my code was trying to delete this system generated permissionsetassignment that I got the errors.

 

Once I changed my select statement to not include the system one, I was no longer getting that error. While I don't know if this will help Crowdcast anymore since it's a post that's 6 months old, but hopefully can help out anyone else running into the same problems.

Sergio MacintoshSergio Macintosh
How did you exclude the system permissionset assignments?
Alexandre MendesAlexandre Mendes

Just had the same issue with the system permissionset assignment, I solved it by inserting in my PermissionSetAssignment query a WHERE condition that would check if the PermissionSetId was the Id of a Permission Set that has the IsOwnedByProfile= FALSE. the system Permission Sets have that value as TRUE.

example query:

SELECT Id, AssigneeId, PermissionSetId
                FROM PermissionSetAssignment WHERE 
                AssigneeId = :userId
                AND PermissionSetId IN (SELECT Id 
                                                      FROM PermissionSet
                                                     WHERE IsOwnedByProfile =false)];

Heiko KrämerHeiko Krämer
SELECT AssigneeId, PermissionSetGroupId, PermissionSetId 
  FROM PermissionSetAssignment 
 WHERE AssigneeId = :sourceUserId
   AND PermissionSet.IsOwnedByProfile = false

Thank you guys, had the same issue, "PermissionSet.IsOwnedByProfile = false" worked for me.
Shraddha Parab 14Shraddha Parab 14
Thank you guys, this helped me too. 
Adding  
AND PermissionSetId IN (SELECT Id 
                                                      FROM PermissionSet
                                                     WHERE IsOwnedByProfile =false)
resolved the error. 
MoggyMoggy

That was very helpful thanks

But it isn't just the permission Set guys also the licensed one's 

Here a quick Devconsole cleanup if it helps

List<PermissionSetAssignment> pms = [Select id,permissionsetId,permissionset.label from PermissionsetAssignment
                                    where Assignee.isActive=false AND PermissionSetId IN (SELECT Id 
                                                      FROM PermissionSet
                                                     WHERE IsOwnedByProfile =false)];
for(PermissionsetAssignment pm :pms){
    system.debug('ID : ' + pm.id + ' Name: '+pm.permissionset.label);
}
List<PermissionSetLicenseAssign> pmsA = [Select id,permissionsetLicenseId,permissionsetLicense.masterlabel from PermissionSetLicenseAssign
                                    where Assignee.isActive=false];
for(PermissionSetLicenseAssign pma :pmsA){
    system.debug('ID : ' + pma.id + ' Name: '+pma.permissionsetLicense.Masterlabel);
}
delete pms;
delete pmsa;