5

So I'm aware that there is a method on UserInfo called isCurrentUserLicensed which lets you check if the user running the code has a licence for a namespace that you specify, i.e. for a particular managed package.

What I want to know is whether there is a way I can test to see if some other user (assume I have their ID) has a licence for a particular package. Has anybody found a way to do this?

8

This is possible by querying on the UserPackageLicense object, available as of Summer 14, as described in my answer to this post:

Get the list of users licensed for a managed package

private static boolean IsUserLicensedForPackage(
    String userId, String packageNamespace
) {
   return [
       SELECT count() 
       FROM UserPackageLicense 
       WHERE PackageLicense.NamespacePrefix = :packageNamespace 
       AND UserId = :userId limit 1
   ]==1;
}

User u = [select Id from User where Name = 'Grace Hopper' limit 1];

System.debug('Does Grace have a license? ' +
    IsUserLicensedForPackage(u.Id,'skuid') ? 'Yes!' : 'No :('
);
| improve this answer | |
2

I know of no inbuilt way to do this (Although my employer is absolutely desperate for it).

The way that we track if a user is licensed for our managed package is whether or not they have one of our permission sets assigned to them.

However there is one enormous caveat. If the license for the managed package is revoked, the permission set remains assigned to the user. This is a significant drawback and can result in false positives, but short of a screen scraping solution it's all we've got.

There is an idea on the idea exchange that is close to what you are trying to achieve.

| improve this answer | |
  • @jeremykraybill suggested something similar earlier when I talked to him; each user with a licence needs to visit some page to 'activate' it, i.e. put their ID into a custom setting somewhere as valid. It would still have the same issue for revoked licences I guess. Seems like a massive whole with managed packages to me. – Matt Lacey May 17 '13 at 5:37
  • It is a painfully frustrating hole. If I was going to implement your activate page, I would use a checkbox on the user object (This is another way we have used to identify licensed users) – Daniel Blackhall May 17 '13 at 6:12
  • Thing with a checkbox is it could still be abused by an administrator... a protected custom setting would be invisible to the installing org. – Matt Lacey May 17 '13 at 7:18
  • 1
    I'm accepting this answer because after doing a whole pile of research it seems there is no way to do this. There are various options which come close such as the above, but nothing fool proof and nothing which guarantees accuracy over time. – Matt Lacey May 20 '13 at 3:41
  • 1
    @Shane I updated the other answer to be the accepted one a while ago - it didn't when I wrote these comments! – Matt Lacey May 13 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.