Auto Assign Package License to New Users

Auto Assign Package License to New Users

Last Updated on March 28, 2022 by Rakesh Gupta

Big Idea or Enduring Question:

  • How can you automatically assign a managed package license to new users?

Objectives:

After reading this blog post, the reader will be able to:

  • Use Flow to automatically add a package license to new users
  • Use get records element to avoid hard code of Id
  • Use decision element to validate the data
  • Understand how to use Flow to create records

Business Use case

Pamela Kline is working as a System administrator at Universal Containers (UC). They are using Conga Composer to streamline and scale their document generation process. She has received a requirement from the management to auto-assign Conga Composer license to new users. Which helps them to minimize the post-user creation manual activities.

Automation Champion Approach (I-do):

A few months back, I had written an article Automatically Add User to a Chatter Group) to discuss a way through which you can automatically add new users to Chatter Group. To achieve it, we used Salesforce Flow.

I got really good feedback from all of you and a few of them requested to explain a way through which they can automate the package license assignment process. In this blog post, I will walk through setting up a Salesforce Flow to automate the package license assignment process.

To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario.

Let’s take a pause here, familiarize yourself with the UserPackageLicenseobjects and PackageLicense objects in Salesforce. 

Object Name Details
UserPackageLicense It represents a license of an installed managed package, assigned to a specific user.
PackageLicense It represents a license of an installed managed package.

Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes going through the following Flow diagram and understand it.


Let’s begin building this automation process.

Guided Practice (We-do):

There are 6 steps to solve Pamela’s business requirement using Record-Triggered Flow. We must:

  1. Define flow properties for record-triggered flow
  2. Formula to determine whether the user is created or updated
  3. Add a decision element to check the outcome of the above formula 
  4. Add a get records element to find Conga Composer package license id
  5. Add a decision element to check if Conga Composer license was found or not 
  6. Add a create records element to assign package license to new user

Step 1: Define Flow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Record-Triggered Flow option, and click on Create and configure the flow as follows:
    1. Object: User
    2. Trigger the Flow When: A record is created or updated
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 2: Formula to Determine Whether the User is Created or Updated

  1. Under Toolbox, select Manager, then click New Resource to determine whether the record is new or old.
  2. Input the following information:
    1. Resource Type: Formula
    2. API Name: forB_IsNew
    3. Data Type: Boolean
    4. Formula: IsNew()
  3. Click Done.

Step 3: Using Decision Element to Check if User is Active and Just Created 

Now we will use the Decision element to check if the user is just set up and it is active. 

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.IsActive}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
    2. Add Condition
    3. Row 2
      1. Resource: {!forB_IsNew}
      2. Operator: Equals
      3. Value: {!$GlobalConstant.True}
  5. When to Execute Outcome: If the condition requirements are met.
  6. Click Done.

Step 4: Adding a Get Record Element to Find Conga Composer Package License id

The next step is to use the Get Records element to get the Conga Composer installed package Id.

  1. On Flow Designer, below the Get Records node, click on the +icon and select the Get Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Select the Package License object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: NamespacePrefix
      2. Operator: Equals
      3. Value: APXTConga4
  6. How Many Records to Store:
    1. select Only the first record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click Done.

To find the Namespace Prefix of installed packages, navigate to Setup | Apps | Packaging | Installed Packages, as shown in the following screenshot:

Namespace Prefix

Step 5: Using Decision Element to Check If Conga Composer license was Found or Not (from step 4)

Now we will use the Decision element to check the Record Variable from step 4 to find if it returns the package license id or not.

  1. On Flow Designer, click on the +icon and select the Decision element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Under Outcome Details, enter the Label the API Name will auto-populate.
  4. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!Conga_Composer_Package_License_Id}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
    2. Click Done.

Step 6: Add Create Records Element to Assign Package License to New Users

The final step is to assign the Conga PackageLlicense to the new users. 

  1. On Flow Designer, below the License Found node, click on the +icon and select the Create Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Input the following information:
    1. How Many Records to Create: One
    2. How to Set the Record Fields: Use separate resources, and literal values
    3. Object: User Package License
    4. Set Field Values for the User Package License
    5. Row 1:
      1. Field: PackageLicenseId
      2. Value: {!Conga_Composer_Package_License_Id.Id}
    6. Click Add Field
    7. Row 2:
      1. Field: UserId
      2. Value: {!$Record.Id}
  4. Click Done.

In the end, Pamela’s Flow will look like the following screenshot:


Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 54
  5. Interview Label: Assign Conga Package License {!$Flow.CurrentDateTime}
  6. Click Save

Almost there! Once everything looks good, click the Activate button.  

Proof of Concept

Now onwards, when a user account is created, Salesforce Flow will automatically trigger and add a package license (Conga Composer) to the newly created user. Let’s test it out.

  1. Now create a new user via the UI
  2. Once the user is created, our automation will automatically assign the package license to the newly created user. To Validate You can either query on the User Package License object or navigate to Setup | Apps | Packaging | Installed Packages | Conga Composer | Manage Licenses. 

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

14 thoughts on “Auto Assign Package License to New Users

  1. Hi, how do you test in sandbox the auto-assign package license thru flow if managed packages related list where you assign the licenses in User setup is not available?

  2. Rakesh Hi,
    Thank you very much for the useful post.
    Can you elaborate the reason you’ve added a Time Based Action?

    Furthermore, can you explain how to auto remove a package license from a deactivated user? (once he is deactivated, the license will be removed from his user).

    Thanks!
    Gidi

  3. Thank you for quick response.
    So, Use Record Lookup for Package, connect to Record look up Permission set, Connect to Record create user? I am trying to assign data.com to users who are or will be assign to 3 different permission sets. with monthly 300 limits.

    1. What i am trying to explain, first use Record lookup element to find if he permission sets is already assign or not. Then go ahead and assign Package License

  4. Hi Rakesh, You have always been a help. I have qq;
    Is it possible to assign package license only to users that are assign to certain permission sets?

    Thank you in Advance!!

    1. Glad to know 🙂

      To assign package license only to users that are assigned to a certain permission set, follow the instructions below

      1. Use Record Lookup element (on PermissionSetAssignment object) for that particular user. Store the ID in a variable – PSAID
      2. Then use Decison element to check PSAID varibale. If it is blank then stop here else connect it to the rest of the Flow

  5. Hi Rakesh,

    This is a great blog you have here. I always look up to this blog for automation related issues. Thank you very much for taking time to put together such easy and clear steps for automating stuff.

    Quick question – i do not see the object ‘PackageLicense’ in the flow. Is that removed? or renamed?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.