Creating the User Group and assigning the roles for the user group
1.Creating the UserGroup: We can get the userId and companyId from themeDisplay. UserGroup userGrp = UserGroupLocalServiceUtil.addUserGroup(userId, companyId, "Test User Group", "Test User Group Desc"); 2.Assiging the user to UserGroup: Here we can assign group of users but as of now we are assigning the only one user. UserLocalServiceUtil.addUserGroupUsers(userGrp.getUserGroupId(), new long []{userId}); 3.Assiging the roles to the usergroups: Here we are getting the groupId of the UserGroup and also the role long groupId =userGrp.getGroup().getGroupId() Role roleId = RoleLocalServiceUtil.getRole(companyId, "Power User"); RoleLocalServiceUtil.addGroupRole(groupId, roleId);