Dynamically Assign an S-Docs License to the Current User
public class SDAssignLicenseController {
public String statusMsg {get;set;}
public void assignLicense() {
Id sdocPkgId = [SELECT Id FROM PackageLicense WHERE NameSpacePrefix='SDOC' AND Status='Active'].Id;
String userId = UserInfo.getUserId();
List<UserPackageLicense> existingUPL = [SELECT Id FROM UserPackageLicense WHERE PackageLicenseId=:sdocPkgId AND UserId=:userId];
if (!existingUPL.isEmpty()) {
statusMsg = 'User already has an S-Docs license.';
return;
}
insert new UserPackageLicense(PackageLicenseId=sdocPkgId, UserId=userId);
statusMsg = 'Successfully assigned user S-Docs license.';
}
}<apex:page controller="SDAssignLicenseController">
<apex:form id="form">
<apex:commandButton value="Get S-Docs License" action="{!assignLicense}" rendered="{!statusMsg == null}" reRender="form" />
{!statusMsg}
</apex:form>
</apex:page>Last updated
Was this helpful?

