Hi everyone, I'm working with a managed package installed in our org. We have a few licenses assigned to users, but we also want to support cases where the org has a Site License (so the package is available to all users without individual assignments).
My goal: I want to conditionally show a Lightning component only if:
- The org has a Site License, OR
- The current user has a license individually assigned.
I already know how to check if the current user has a license using UserPackageLicense, but I can't find a reliable way to check whether the org has a Site License for the package.
Question: 👉 How can I check in Apex whether the org has a Site License for a specific managed package?
Thanks in advance!
Query the PackageLicense object to get information about the total allowed licenses and used licenses for the package.
String packageNamespace = 'your_package_namespace'; // Replace with your package's namespace
PackageLicense packageLicensing = [
SELECT AllowedLicenses, UsedLicenses
FROM PackageLicense
WHERE NamespacePrefix = :packageNamespace
LIMIT 1
];
Boolean hasSiteLicense = false;
if (packageLicensing != null && packageLicensing.AllowedLicenses > 10000000) { // Adjust the threshold as needed
hasSiteLicense = true;
}