For the complete documentation index, see llms.txt. This page is also available as Markdown.

Dynamically Assign an S-Docs License to the Current User

Use Case: This is useful in an org that has a ton of users. You can create a custom VF page (name it something like SDGetLicense) that a user can visit and click a button on to be assigned an S-Docs License. This self-service option eliminates the need for admins to manually assign a ton of licenses to specific users.

SDAssignLicenseController.cls
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.';
   }
}
SDGetLicense.page (Visualforce)
<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?