I'm developing a managed package and I need the list of users with the license for the managed package within the package.

Any idea on where to start will help!

Overriding a standard button depending on whether user is licensed

This gave me some insight that I cannot use UserInfo object within the app. Am I on the right path?

  • It seems like the post you linked to is exactly the answer: you cannot access them from your managed package...at least not from a visualforce page, since in order for your code to be executed, they have to have the managed package license in the first place.
    – pchittum
    Nov 25, 2013 at 17:05
  • @Peter : Yes. I need a work around to get the list of users with the license for that managed package. Even if I can get that information outside the package, that'll be great! I'm just wondering if that can fetched from User record using Apex. Nov 26, 2013 at 1:02
  • 4
    An Idea for this has been created in the IdeaExchange: success.salesforce.com/ideaView?id=08730000000bj7xAAA
    – BarCotter
    Dec 3, 2013 at 19:54

4 Answers 4


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 
   LIMIT 1
  • Awesome!!! So much needed! I believe this is the best answer. You have my vote up, man. Thanks a lot.
    – Patlatus
    Apr 3, 2015 at 17:02
  • I thought I would have to do screen scraping... Luckily not. This answer answers completely this question.
    – Patlatus
    Apr 3, 2015 at 17:04

Thoughts. As has been pointed out the UserInfo.isCurrentUserLicensed is of course for the current user, and since you can only impersonate users in a test context your out of luck here. I've had a look through the Salesforce API documentation to determine if there is any query able metadata about this and I didn't find any. I also considered the Metadata API, nothing here either. Shame as both of these could feasibly have been called from Apex if they did present a solution.

Conclusion and Recommendation for Salesforce. My conclusion is thus sadly for you, this is not possible, it would be a good use case for the Metadata API in my view, as a natural extension to the InstalledPackage component to contain a list of users.

But wait...never say never... so.... of course you can scrape the list of users from the Salesforce page itself, there are a few answers such as this one (screen scrape Salesforce with REST GET call from Apex) that go into more details on this approach. Wash thoroughly after reading this bit! ;-)


enter image description here

Alternative Approach: If you cannot get the list directly you may have to end up adding a checkbox to the User object, and asking those that assign Licenses to ensure it is checked and unchecked accordingly as part of their process. Its hopefully not something that is that frequent a task for this to be an overly big ask. Then you can use this in your code and/or in something like a Lookup Filter over the User.

  • Wonderful! But yeah, scraping the page is not an advisable solution as you suggested.Hoping to find a work around. Fingers crossed! Nov 28, 2013 at 13:51
  • Indeed. So is it just a basic list you want or something more? Is there a reason why the standard UI Salesforce provides is not suitable? Nov 28, 2013 at 14:36
  • I just need the list of users because my business functionality needs cases to be assigned to those users who have the license to the package. I said this is not a suitable solution because the DOM structure of the page might change in the future leading to a new release to be pushed to all the existing users(orgs). Nov 28, 2013 at 15:03
  • 2
    I see, yeah you might in the end have to maintain this as a checkbox on the User record and use a Lookup filter perhaps? And yeah, spot on with the screen scrape, sometimes "just because you can, doesn't mean you should!" ;-) Nov 28, 2013 at 15:07

Vignesh, I should put that custom button in another package, let's call it OptionsPack. Make OptionsPack unmanaged i.e. with no license, runnable by all, make it an extension package dependent on your package. Also, make sure that the stuff it calls is global in your package.

That button can now get UserInfob and inspect its licensing.

  • I'll get to know if the current user is licensed or not using the "UserInfo.isCurrentUserLicensed()" but what I need is a list of users having license to the package. Nov 28, 2013 at 7:17
  • Like Andrew, I suggest you go for the checkbox on User. Certainly.
    – altius_rup
    Nov 29, 2013 at 3:06

Just go to Setup->Install package->Package name->click Manage Licenses

you will get the list of users assigned

Hope this helps anyone in the world


  • 1
    Welcome to Salesforce Stack Exchange (SFSE). Your contribution is welcome. However, while your answer may technically answer the question in the title, it does not fully address the OP's actual question as detailed - which is, essentially, how to programmatically retrieve that list from within the managed package code itself, not manually find the list. There is a chance that your answer will be deleted - take the SFSE Tour & read more in the Help Center. And be sure to keep reading and contributing!
    – Moonpie
    Apr 21, 2022 at 16:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .