Any permission set to any user whose profile is changing. No specific one Need a code for general use, on the basis of salesforce best practice, as soon as possible.
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])
{
PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = '0PSq00000009qDNGAY', AssigneeId = u.Id);
permissionSetList.add(psa);
}
try{
upsert permissionSetList;
}
catch(exception e){
}
Thanks,
Need a code for general use, on the basis of salesforce best practice, as soon as possible.
Check below references.
https://developer.salesforce.com/forums/?id=9060G000000I6XjQAK
https://jenwlee.com/2020/03/10/draft-permission-set-group-assignment-automation/
Thanks,