2

This question already has an answer here:

I want to enable licensing for my managed package and had few questions:

The licensing would be on a per user basis. My managed package runs a scheduled job in system context and performs some operations for Users which are licensed.

  • How can I check license for a set of users other than current user?

  • I'm aware that we can check licenses for the current user. But checking for licenses for X number of users would require a DML operation in every run. What are the best practices for checking for licensed users?

  • How does LMA work for such cases?

  • How do you write unit tests for licensed users before security review? Since you do not have access to LMA org?

marked as duplicate by Daniel Ballinger, Santanu Boral, martin, Ratan Paul, Tushar Sharma May 3 '17 at 5:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

How can I check license for a set of users other than current user?

Use UserPackageLicense:

SELECT UserId FROM UserPackageLicense WHERE PackageLicense.NamespacePrefix = 'your_prefix'

I'm aware that we can check licenses for the current user. But checking for licenses for X number of users would require a DML operation in every run. What are the best practices for checking for licensed users?

You mean a SOQL operation, right? Yes, you'll have to check this every time if you need to know everyone involved. This might require kicking off a batch if you want to avoid governor limits. There's no best practice for this, because this a fairly uncommon use case, and accordingly, there's no real "API" for this.

How does LMA work for such cases?

It doesn't have anything to do with this. LMA just allows you to specify the number of licenses and the expiration date.

How do you write unit tests for licensed users before security review? Since you do not have access to LMA org?

You should be able to insert UserPackageLicense record in your developer org having an LMA isn't a prerequisite to having a namespace. I have a few developer orgs with namespaces that are not LMA-enabled.

1

You can use a combination of PackageLicense and UserPackageLicense to find the details you need.

The UserPackageLicense records will be linked to the PackageLicense via the PackageLicenseID field. Use your Namespace Prefix to find the PackageLicense.

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