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:
- Define flow properties for record-triggered flow
- Formula to determine whether the user is created or updated
- Add a decision element to check the outcome of the above formulaÂ
- Add a get records element to find Conga Composer package license id
- Add a decision element to check if Conga Composer license was found or notÂ
- Add a create records element to assign package license to new user
Step 1: Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flow option, and click on Create and configure the flow as follows:
- Object: User
- Trigger the Flow When: A record is created or updated
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.
Step 2: Formula to Determine Whether the User is Created or Updated
- Under Toolbox, select Manager, then click New Resource to determine whether the record is new or old.
- Input the following information:
- Resource Type: Formula
- API Name: forB_IsNew
- Data Type: Boolean
- Formula: IsNew()
- 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.Â
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.IsActive}
- Operator: Equals
- Value: {!$GlobalConstant.True}
- Add Condition
- Row 2
- Resource: {!forB_IsNew}
- Operator: Equals
- Value: {!$GlobalConstant.True}
- Row 1:
- When to Execute Outcome: If the condition requirements are met.
- 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.
- On Flow Designer, below the Get Records node, click on the +icon and select the Get Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Select the Package License object from the dropdown list.
- Select All Conditions Are Met (AND).Â
- Set Filter Conditions
- Row 1:
- Field: NamespacePrefix
- Operator: Equals
- Value: APXTConga4
- Row 1:
- How Many Records to Store:
- select Only the first record
- How to Store Record Data:
- Choose the option to Automatically store all fields.Â
- Click Done.
To find the Namespace Prefix of installed packages, navigate to Setup | Apps | Packaging | Installed Packages, as shown in the following screenshot:
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.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome:Â All Conditions Are Met (AND)
- Row 1:
- Resource: {!Conga_Composer_Package_License_Id}
- Operator: Is NullÂ
- Value: {!$GlobalConstant.False}
- Click Done.
- Row 1:
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.Â
- On Flow Designer, below the License Found node, click on the +icon and select the Create Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- Input the following information:
- How Many Records to Create: One
- How to Set the Record Fields: Use separate resources, and literal values
- Object: User Package License
- Set Field Values for the User Package License
- Row 1:
- Field: PackageLicenseId
- Value: {!Conga_Composer_Package_License_Id.Id}
- Click Add Field
- Row 2:
- Field: UserId
- Value: {!$Record.Id}
- Click Done.
In the end, Pamela’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:Â
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 54
- Interview Label: Assign Conga Package License {!$Flow.CurrentDateTime}
- 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.
- Now create a new user via the UI
- 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.
HI can we assign a package license to a user on a temporary basis.
The simple answer is no unless you build automation to auto-remove the package license.
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?
how to assign license to users automatically once package is installed.(not when a user is created/inserted)
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
1. To overcome – Mixed DML operation issue
2. Refer this article Getting Started with Process Builder – Part 79 (Auto Remove Managed Package License from a Deactivated User!)
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.
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
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!!
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
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?
Thank you. I am glad you liked my article 🙂
You can access PackageLicense object either from Flow or Apex.
Great blog Rakesh! Is it possible to add permission sets to a new user automatically based on role?
Thank you 🙂
Here you go “Automatically add Permission Sets to new User“