function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sriram k 15sriram k 15 

When User created then need to assign permission set automatically based on profile.?

Need to achive this scenario by Apex coding. 
AbhinavAbhinav (Salesforce Developers) 
Hi Sriram,

Have you check suggestion on below link?

Arfiyan Shaikh 7Arfiyan Shaikh 7
Hi Sriram,

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];
        List<string> existingRealAllUserList = new List<string>();
        List<PermissionSetAssignment> FunnelReadAll = [Select AssigneeId FROM PermissionSetAssignment WHERE  PermissionSet.Name = :PermissionSetName];
        for(PermissionSetAssignment p: FunnelReadAll){
        List<User> userList =[Select id   from User Where IsActive = true AND id IN :userIds];
        for(User s : userList){
            PermissionSetAssignment psa = new PermissionSetAssignment (PermissionSetId =, AssigneeId =;
        if(permissionSetList != null)
            upsert permissionSetList;
        }catch(exception e){
            system.debug('exception caught' + e);