You need to sign in to do that
Don't have an account?
sriram k 15
When User created then need to assign permission set automatically based on profile.?
Need to achive this scenario by Apex coding.
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Have you check suggestion on below link?
https://developer.salesforce.com/forums/?id=906F0000000BDYtIAO
Thanks!
You can write a trigger on User object and use below code to assign permission set
String PermissionSetName = 'ReadAll';
List<id> userIds = new List<id>(); // list of id's from the trigger
List<PermissionSetAssignment> permissionSetList = new List<PermissionSetAssignment>();
PermissionSet readAllpermission = [SELECT Id ,name FROM PermissionSet where name = :PermissionSetName];
System.debug('readAllpermission:::'+readAllpermission);
List<string> existingRealAllUserList = new List<string>();
List<PermissionSetAssignment> FunnelReadAll = [Select AssigneeId FROM PermissionSetAssignment WHERE PermissionSet.Name = :PermissionSetName];
for(PermissionSetAssignment p: FunnelReadAll){
existingRealAllUserList.add(p.AssigneeId);
}
System.debug('existingRealAllUserList:::'+existingRealAllUserList);
List<User> userList =[Select id from User Where IsActive = true AND id IN :userIds];
for(User s : userList){
if(!existingRealAllUserList.contains(s.id)){
PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId = readAllpermission.id, AssigneeId = s.id);
permissionSetList.add(psa);
}
}
try{
if(permissionSetList != null)
upsert permissionSetList;
}catch(exception e){
system.debug('exception caught' + e);
}