Use Case: As a Salesforce Administrator, you are requested to set an email alert when all the available Salesforce User Licenses in your organization are assigned to users. This way, your manager/HR team will be notified to get more user licenses when new employees are being hired.
Key Object:
UserLicense – Represents a user license in your organization.
Fields we need from this object:
Name – The name of user license.
TotalLicenses – The number of user licenses in the organization.
UsedLicenses – The number of user licenses that are assigned to active users in the organization.
Here is the object reference for UserLicense object
Solution:
Create a Custom Label to store email address to whom the email need to be sent
1. Setup => Custom Labels => New Custom Label
2. Provide Short Description and Name
3. Value – enter the email address [for multiple email addresses enter comma-separated]
4. Click Save [Will use this Custom Label in Step 10.7]
Step 1. Navigate to Flow and start building it
1. Click Setup.
2. In the quick find box, enter Flows.
3. Select Flows and then click on New Flow.
4. Select Schedule-Triggered Flow option.
5. Click Next and select Freeform.
Step 2. Add Text Variable to store User License Name
1. Under Toolbox => Manager => New Resource
2. Select Resource Type – Variable
3. API Name – varLicenseName
Tip: Always provide a description so you and other/future admins know what this is used for.
4. Data Type – Text
5. Default Value – Salesforce [as we are setting up email alert for threshold of Salesforce User Licenses, I’m providing default value as Salesforce]
6. Click Done

Note: You can skip step2 and create Custom Label to store Salesforce value in it and use this custom label in step 3.5
Step 3. Get Records
1. Under Toolbox => Elements => Drag and drop Get Records element on to the canvas.
2. Enter Label getUserLicenses and API Name should populate automatically.
TIP: Always provide description, it helps you and other admins to refer later.
3. Select Object – User License.
4. Condition Requirements – All Conditions Are Met (AND)
5. Set condition: Field – Name, Operator – Equals , Value – {!varLicenseName}
6. How Many Records to Store – All Records
7. How to Store Record Data – Automatically store all fields
7. Click Done

Step 4. Loop Element
1. Drag and drop Loop element on to the canvas
2. Enter Label and API Name should populate automatically
Tip : Don’t forget to provide a description so you and other/future admins know what this is used for.
3. Set Collection Variable – {!getUserLicenses}
4. Specify Direction for Iterating Over Collection – First item to last item
5. Click Done
6. Connect Get Records element and Loop element

Step 5. Add Number Variable to store Total Salesforce User Licenses
1. Under Toolbox => Manager => New Resource
2. Select Resource Type – Variable
3. API Name – varTotalLicenses
Tip : Provide description so you and other/future admins know what this is used for.
4. Data Type – Number
5. Decimal Places – 0
6. Click Done

Step 6. Add Number Variable to store Used Salesforce User Licenses
1. Under Toolbox => Manager => New Resource
2. Select Resource Type – Variable
3. API Name – varUsedLicenses
Tip : Provide description so you and other/future admins know what this is used for.
4. Data Type – Number
5. Decimal Places – 0
6. Click Done

Step 7. Assignment Element
1. Under Toolbox => Elements => Drag and drop Assignment element on to the canvas
2. Enter Label and API Name should populate automatically
3. Provide description
4. Set Variable Values –
Variable. => {!varTotalLicenses}
Operator => Add
Value => {!loopUserLicenses.TotalLicenses}
5. Click Add Assignment
Variable => {!varUsedLicenses}
Operator => Add
Value => {!loopUserLicenses.UsedLicenses}
6. Click Done

7. Connect Loop element and Assignment element
8. Select loop connector – For each item in the collection
9. Click Done

10. To close the open loop, connect the last element in the loop back to the “loopUserLicenses” Loop element.
Step 8. Decision Element to create a decision and set outcomes
1. Under Toolbox => Elements => Drag and drop Decision element on to the canvas
2. Enter Label Check Licenses and API Name will populate automatically
3.Provide description
4. For New Outcome –
Label – used=total
Outcome API Name will populate automatically
Condition Requirements to Execute Outcome – All Conditions Are Met (AND)
Resource – {!varUsedLicenses}
Operator – Equals
Value – {!varTotalLicenses}
5. Click Done
6. Connect Loop element to Decision element

Till now, we got all user license records and stored total licenses and used licenses values and set a condition in decision element to check used licenses and total licenses are equal or not? , If that is true then we need to send an email mentioning there are none available salesforce user licenses.
Step 9. Create Text Templates to use in email action
1. Under Toolbox => Manager => New Resource
2. Select Resource Type – Text Template
3. API Name – ttEmailBody
Tip: Always provide a description
4. Select View as Plain Text
5. Body – See the screenshot below
6. Click Done

Step 10. Action element to send email alert
1. Under Toolbox => Elements => Drag and drop Action element on to the canvas
2. Action – Search for Send Email and select it
3. Enter Label and API Name will populate
4. Provide description
5. Body – {!ttEmailBody}
6. Subject. – REMINDER : Salesforce User Licenses
7. Email Addresses (comma-separated) – {!$Label.Flow_Emails}
8. Click Done

9. Connect Decision element to Action
10. Select outcome for decision connector – used=total
11. Click Done

Now we are almost done. we need to schedule this flow by setting up Start Date, Start Time and Frequency[Once, Daily, and Weekly]

Here is the final flow:

Step 11. Save the Flow
1. Click Save on top right
2. Enter Flow Label and API Name will populate automatically
3. Click Save
Let’s test this:
In my developer org, I have total of two Salesforce User Licenses and those two are in use.

In our flow decision element, we set the condition to Total Licenses equals used Licenses, Output will be the send email action.
Email Output:

Thanks for reading!!
Hi, I tried to replicate this but I don’t receive the email. Could you help me out?
LikeLike
Hi Sebastian. 1. Check whether Deliverability was set to All Email. 2. Make sure you have all Salesforce licenses assigned.
3. Make sure you didn’t provided incorrect email.
Check debug logs.
It’s really hard to say without seeing the flow.
LikeLike
Thank you for your help! Can I have your email in order for me to send you a screenshot of the flow? It would be easier for you to assist me, if you want of course. My email is sebastian.toccalino@mercadolibre.com in case you want to write me and I’ll send the screenshot.
Thanks again for your help!
LikeLike