HI Aditi, The below code can be used to Assign Permission Set to Users
List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
for (User u : [SELECT ID,UserRole.Name,Profile.Name,IsActive FROM User WHERE UserRole.Name LIKE '%manager%' AND Profile.Name != 'Operations Manager' AND IsActive = true]){ // Add fields as per your requirement...
PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = '0PSq00000009qDNGAY', AssigneeId = u.Id);
permissionSetList.add(psa);
}
try{
upsert permissionSetList;
}catch(exception e){
system.debug('exception caught' + e);
}
You can change the SOQL query as per your requirement. Related:https://salesforce.stackexchange.com/questions/60668/assigning-permission-set-to-user-in-apex https://salesforce.stackexchange.com/questions/130174/can-i-assign-permission-set-to-a-profile-instead-of-user
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
The below code can be used to Assign Permission Set to Users
You can change the SOQL query as per your requirement.
Related:https://salesforce.stackexchange.com/questions/60668/assigning-permission-set-to-user-in-apex
https://salesforce.stackexchange.com/questions/130174/can-i-assign-permission-set-to-a-profile-instead-of-user
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you