Please chekc below code and let me know if it works !!
List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
Id permissionSetId=[SELECT id FROM permissionSet WHERE Name ='permissionSetName'].id;
Set<String> profileSet= new Set<String>{'xxx','yyy','ZZZ'};
for (User u : [SELECT ID,UserRole.Name,Profile.Name,IsActive FROM User WHERE UserRole.Name IN:profileSet AND IsActive = true]){ // Add fields as per your requirement...
PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = permissionSetId, AssigneeId = u.Id);
permissionSetList.add(psa);
}
try{
upsert permissionSetList;
}catch(exception e){
system.debug('exception caught' + e);
}
Please chekc below code and let me know if it works !!
List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
Id permissionSetId=[SELECT id FROM permissionSet WHERE Name ='permissionSetName'].id;
Set<String> profileSet= new Set<String>{'xxx','yyy','ZZZ'};
for (User u : [SELECT ID,UserRole.Name,Profile.Name,IsActive FROM User WHERE UserRole.Name IN:profileSet AND IsActive = true]){ // Add fields as per your requirement...
PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = permissionSetId, AssigneeId = u.Id);
permissionSetList.add(psa);
}
try{
upsert permissionSetList;
}catch(exception e){
system.debug('exception caught' + e);
}
Please chekc below code and let me know if it works !!
Thanks ,
Manoj
All Answers
Please chekc below code and let me know if it works !!
Thanks ,
Manoj