As of Summer 14, there are 2 new objects which allow you to use SOQL to see which users are licensed for particular Managed Packages: PackageLicense
and UserPackageLicense
.
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 UserPackageLicense
object supports DML as well, so you could add triggers on User after insert/update that either assign available licenses on User activation or revoke licenses on User deactivation.
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
];