Auto Remove Managed Package License from a Deactivated User!

Auto Remove Managed Package License from a Deactivated User!

Last Updated on April 14, 2022 by Rakesh Gupta

Salesforce Flow is a fantastic way to automate various business processes. It allows you to create a flow based on certain criteria that you set. Salesforce flow can do many things – Create a record, Update records, Post to Chatter, Send an email, etc.

A few years back – in September 2015 – I wrote an article Auto Assign package license to New user to show how one can automatically assign managed package license to new users. 

The overwhelming positive feedback was followed by requests – to write another blog showing how to automatically remove managed package license from the deactivated user(s)! Below is one of the sample emails – from a gentleman whom I know not, but would like to thank for making the request. For, requests and ideas from my blog readers have immensely contributed to my mastery of the Salesforce Platform!

I am looking for a way to automatically delete an installed package members whenI inactivate their User account. Currently, I have to delete the User; then delete them from the installed package. Is there a way via PB and/or Flow? I'd like an automated deletion process that captures all associations.

Thank you,
Erin Ryan

In this blog post, I will show you how to leverage salesforce flow to automatically remove managed package licenses from deactivated users. Let us start with a business use case.

Business Use Case

Martin Jones is working as a System Administrator at Gurukul on Cloud (GoC)At GoC they are using  Conga Composer to streamline and scale their document generation process. Martin received a requirement from the management to auto-remove managed package licenses as soon as a user’s account is deactivated.

Prerequisite

Please go through this article first and make sure to complete the listed steps: Auto Assign Package License to New Users.

Solution for the above business requirement

Before we proceed, let us first ponder – why do we need to automate this process in the first place?  On AppExchange, App providers use managed packages, partly, to hide the code and implementation logic from customers. Another benefit of a managed package is that app providers can easily push updates to their customers’ org in one stroke.  

When a user’s account is deactivated in Salesforce, his/her Salesforce license is released and available for reassignment. Such is not the case vis-a-vis the deactivated user’s managed package license. Despite being deactivated, a user’s managed package license is not automatically removed from his/her account; the System Administrator has to manually remove the managed package license from the deactivated user’s account.

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 5 steps to solve Martin’s business requirement using Record-Triggered Flow. We must:

  1. Clone record-triggered flow created in Auto Assign Package License to New Users
  2. Add an OUTCOME ORDER in the decision element to check if the user account has been deactivated 
  3. Add a get records element to find assigned manage package licenses 
  4. Add a decision element to check if the manage package license was found or not 
  5. Add a delete records element to remove manage package licenses 

Step 1: Clone a Flow

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the Flow Name that will be modified. In this case Assign Conga Package License.
  4. Click on the Save As button at the top right of the Flow builder.
  5. Once you are done, click on the Save button.

Step 2: Add an OUTCOME ORDER in the Decision Element to Check the User Account Status 

Now we will use the Decision element to check if the user has been deactivated.

  1. Click on the Created or Updated Decision Element element.
  2. Add a new OUTCOME ORDER by clicking on the + icon. 
  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.False}
  5. When to Execute Outcome: Only if the record that triggered the flow to run is updated to meet the condition requirements.
  6. Click Done.

Step 3: Adding a Get Record Element to Find Assigned Manage Package Licenses

The next task is to check whether a managed package license is assigned to the user. For this, we will use the Get Records element.

  1. On Flow Designer, below the Deactivated User Account 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 User Package License object from the dropdown list.
  4. Select All Conditions Are Met (AND)
  5. Set Filter Conditions
    1. Row 1:
      1. Field: UserId
      2. Operator: Equals
      3. Value: {!$Record.Id}
  6. How Many Records to Store:
    1. select All record
  7. How to Store Record Data:
    1. Choose the option to Automatically store all fields
  8. Click Done.

Step 4: Using Decision Element to Check If Manage Package license was Found or Not (from step 3)

Now we will use the Decision element to check the Record Collection Variable from step 4 to find whether any managed package license is assigned to the user 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: {!Get_User_Package_License}
      2. Operator: Is Null 
      3. Value: {!$GlobalConstant.False}
    2. Click Done.

Step 5: Add Delete Records Element to Remove Assigned Manage Package Licenses

The final step is to add a Delete Records element to remove the assigned package license from the user. 

  1. On Flow Designer, below the Package License Found node, click on the +icon and select the Delete Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. Input the following information:
    1. How to Find Record to Delete: Use the IDs stored in a record variable or record collection variable
    2. Select Record(s) to Delete
      1. Record or Record Collection: {!Get_User_Package_License}
  4. Click Done.

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

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

Proof of Concept

  1. First of all, navigate to the Installed Package and check the licenses used for various apps, as shown below:
  2. Now, deactivate a user’s account to whom you have assigned managed package Conga Composer and DocuSign For Salesforce license. For proof of concept, please refer to the following video:

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!
Preferred Timing(required)

8 thoughts on “Auto Remove Managed Package License from a Deactivated User!

  1. Hi Rakesh

    As this was written in 2018 and flow is evolved.

    Is it possible not to use PB & have everything done in 1 flow ? I think yes but need your input.

  2. Hi,
    I am looking for a way to automatically delete an active campaign when I inactivate campaign owner User account. Is there a way via PB and/or Flow? I’d like an automated deletion process.

    Thank you,

  3. In that case where should I set this condition that if user is inactive and last login is more than 30 days , then remove installed package. As we do not want to remove installed package as soon as user is inactive but wait till 30 days. Also when we are removing , process should again check if user is still inactive.

    Is a way to send email for number of user records impacted?

    1. You have to use time-based action

      1. Fire your process once a user gets inactive
      2. Then use time-based action after 30 days
      3. Use Flow to remove the package license from the user.
      4. Use Static action. – Email in the flow to send notification of system administrator or group of users

  4. can we remove licence after 30 days of user deactivation. As well what is better to use batch job or process builder in this scenario?

    1. Yes you can remove package license after 30days. As you are not going to deactivate lots of users every weeks, I think using process builder in this case make sense

Leave a Reply

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

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading