How does Salesforce handle Managed Package Licences between Packages?

So I have a managed package we’ll call Package Core. It has various components, incl custom fields on Account and Contact. It is licensed by user, and works as expected – no license, no access to the custom fields. I have a second package which is an extension of Package Core. That second package includes a VF page which queries fields in Package Core via JS Remote, and displays them on the page. Accessibility to those fields is checked using IsAccessible as required by Security Review.

But when a non-licensed user of Package Core accesses that VF page in the Extension package, they can see data from the Package Core fields, even though they don’t have a license to those fields. In effect, my Extension package does not seem to respect license management, which seems wrong to me? What check should I be doing to ensure that if a user doesn’t have a license to Package Core, they can’t see the fields when they access them from a Extension Package?

Answer

Have encountered similar limitations as well. Many operations in the dependent package, such as reading and editing these fields, will not require the managed package license. Some however still will, such as creating a Chatter Feed post related to the record which is in the licensed managed package.

If you need to do a programmatic check to enforce the license in your dependent package, you could add an exception or redirect on page load if the current user context does not have a package license.

For example,

private Boolean userHasPackageLicense() {
   List<UserPackageLicense> licenseAssignments = [
        SELECT
            Id
        FROM
            UserPackageLicense
        WHERE
            UserId = :UserInfo.getUserId()
        AND
            PackageLicense.NamespacePrefix = :'MyCoreNamespace'
    ];
    return !licenseAssignments.isEmpty();
}

...

if (!userHasPackageLicense()) {
   throw new ArrMateyException();
}

Attribution
Source : Link , Question Author : BritishBoyinDC , Answer Author : Dan Wuensch

Leave a Comment