List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
for (User u : [SELECT ID FROM User WHERE IsActive=true AND Profile.Name='System Administrator'])
{
PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = '0PS55000000gzpLGAQ', AssigneeId = u.Id);
permissionSetList.add(psa);
}
Upsert permissionSetList;
Note: Only to Active Users we can assign permission sets. In the above query, if we remove the "IsActive=true" filter, you will land up with an error.
Comments
Post a Comment