Magento 2: How to get admin user detail load by id?

You need to add this to your class and constructor:

protected $userFactory;
public function __construct(
    ...
    \Magento\User\Model\UserFactory $userFactory,
    ...
)
{
    ...
    $this->userFactory = $userFactory;
    ...
}

Then create a method in the same class to retrieve the role data:

public function getRoleData($userId)
{
    $user = $this->userFactory->create()->load($userId);
    $role = $user->getRole();
    $data = $role->getData();
    return $data;
}

You can use following code:

$adminuserId = 15;
$user = \Magento\Framework\App\ObjectManager::getInstance()->create(
    'Magento\User\Model\User'
);
$user->load($adminuserId);

But it is not recommended to use ObjectManager directly in the code. Try to add Magento\User\Model\UserFactory to your class constructor and use it to load customer.

Example:

class SomeMyClass
{
    protected $_userFactory;

    public function __construct(
        \Magento\User\Model\UserFactory $userFactory
    ) {
        $this->_userFactory = $userFactory;
    }

    public function someFunction()
    {
        $adminuserId = 15;
        $user = $this->_userFactory->create();
        $user->load($adminuserId);
    }
}

Tags:

Admin

Magento2