List<PermissionSetAssignment> psAssignmentsToRemove = [SELECT Id
FROM PermissionSetAssignment
WHERE PermissionSetGroup.DeveloperName = 'CEC_JTAC_Engineer'
AND Assignee.IsActive = FALSE];
System.debug('Permission Set Assignment #: ' + psAssignmentsToRemove.size()); // Confirm # of users it will be removed from
Integer errorCounter = 0;
Database.DeleteResult[] deletedPSAssignments = Database.delete(psAssignmentsToRemove, false);
for (Database.DeleteResult result : deletedPSAssignments) {
if (!result.isSuccess()) {
errorCounter++;
}
}
System.debug('Assignments not deleted: ' + errorCounter);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter