0

Do either of these exist:

  1. API to get the Managed Packages of the user?
  2. API to set the Managed Packages of the user?

1 Answer 1

5

You can use the UserPackageLicense like a normal object. You can query the object to determine if a user has a given package assigned to them, insert new records to assign a package, and delete them to remove a package. This works both in Apex Code and the various API's (SOAP, REST, etc).

Retrieving

UserPackageLicense[] licenses = [SELECT PackageLicense.NamespacePrefix 
    FROM UserPackageLicense
    WHERE UserId = :UserInfo.getUserId()];

Setting

PackageLicense license = [SELECT Id FROM PackageLicense WHERE NamespacePrefix = :aPrefix];
UserPackageLicense userLicense = new UserPackageLicense(UserId=UserInfo.getUserId(), 
     PackageLicenseId=license.Id);
insert userLicense;

Removing

delete [SELECT Id FROM UserPackageLicense 
     WHERE PackageLicense.NamespacePrefix = :aPrefix AND UserId = :UserInfo.getUserId()];

You must log in to answer this question.

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