EP - 19 | DEACTIVATE USERS USING LAST LOGIN DATE | LIGHTNING FLOW SERIES⚡️

 


Deactivate Users Using Last Login Date

In this blog we will learn how to deactivate users who are not really active which means if you have 100 users and 25 of them have not even logged in from a very long time then what is the use of keeping them active? 

Use Case :

Deactivate Users if the have not logged in from more than 90 days.

Solution : We will use Scheduled Trigger Flow. Why?
Because we don't want to run this flow manually instead we will just set a time on which this will automatically run and deactivate those users.

You can run it daily but I will recommend running it weekly because this will not be useful to check the users daily.

Let's start building our flow.

Step 1 : Select Schedule-Trigger Flow and for "Set Schedule" we will set our start date from whenever you want this to run and for time we will select "12:00 AM". After that for frequency we will select "Weekly".

Step 2 : For Object we will choose "User" and we will add a condition that "isActive" equals to "True". Because if the user is already deactive then what is use of getting them in this flow.

Step 3 : Create a Variable with Record Type "Formula" because we want to create a formula to check the last login date of user. 
For ApiName we will add "LastLoginCheck". Data type will be "DateTime".
For Formula we will add "NOW()-90".
Have a look :


This formula will check if the last login date was before 90 days.

Step 4 : Take a decision element to check if the date was before 90 days with the help of formula field.


In this we will check if $Record > Last Login is Less than or Equal to LastLoginCheck(Formula). If the decision gives true then we will update the user.

Step 6 : If Decision is true then we will add an assignment element to assign $Record values.

Here is the assignment element :


In this for $Record>Active we will add false because we want to deactivate the user and for $Record>Note we will add a note (Create a variable "Note") in which we have written in the description that "The user was not logged in from last 90 days".

Step 7 : Take an Update Record Element to Update the User.


In this we have directly selected the "Use the IDs and all field values from a record or record collection" option and for "Record or Record Collection" we have add $Record because in Step 6 we have updated $records values.

That's it. Now this flow will run weekly and check all the users if their login date was before 90 days then it will deactivate the user.

For Detail video tutorial checkout this link :



If you have any question please leave a comment below.

If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Thanks
Let's learn and grow together.
Love and Peace! 🧡

Post a Comment

0 Comments