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
Ikram Momin 16Ikram Momin 16 

Fetch ManagedPackages assigned to user

Hiii

I am using below query to fetch ManagedPackages assigned to users in org :
SELECT PackageLicenseId, UserId FROM UserPackageLicense

My users query is : 
SELECT Id, Username, LastName, FirstName FROM User

Is there any query to fetch ManagedPackages assigned to users in users query  ?

SwethaSwetha (Salesforce Developers) 
HI Ikram,

I recommend checking the post  https://salesforce.stackexchange.com/questions/21180/get-the-list-of-users-licensed-for-a-managed-package

UserPackageLicense lets you see which users are licensed for a particular package:
String APP_NAMESPACE_PREFIX = 'skuid';

List<User> licensedUsers = [
   SELECT Name 
   FROM User 
   WHERE Id in (
       SELECT UserId 
       FROM UserPackageLicense 
       WHERE (PackageLicense.NamespacePrefix = :APP_NAMESPACE_PREFIX)
   )
];
The PackageLicense object lets you see the stats on the number of licensed users available and currently in use in your org for a particular package, as well as when the app was installed and when it expires:
PackageLicense packageLicensing = [
   SELECT AllowedLicenses, UsedLicenses, 
           ExpirationDate, CreatedDate, 
           IsProvisioned, Status
   FROM PackageLicense 
   WHERE NamespacePrefix = :APP_NAMESPACE_PREFIX
   LIMIT 1
];

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you​​​​
 
Ikram Momin 16Ikram Momin 16
Hi swetha
Below query will provide me Name of users who are assigned with any Managed Packages.Below query will not give me users whom any managedpackage is not assigned
SELECT Name FROM User WHERE Id in ( SELECT UserId FROM UserPackageLicense)

However. I want All Users from Users table along with managedpackage assigned if any.