Use Case: Deactivate Users with The Last Login Date

We have utilized the Schedule-Triggered flow to automate sending the emails. Now, we want to show you how to use Schedule-Triggered flow to automatically deactivate the users! In Flow Builder, there is a standard field for the User object called “Last Login Date“. This field makes the solution very easy to build, so let’s dive in!

* Big thanks to Gustavo Seluja for sending in the case!

Lulu Mobile wants to automate their user management. If a user hasn’t logged in for the past 90 days, they want to deactivate this user automatically. At the same time, they want to add a note of “90 Days No Login” in their custom Note field.

(Assumption: There is a “Note” text field on the User object)

We will use the Schedule-Triggered flow. In the automate email post, we created a formula field and let it run daily. However, we cannot do the same for the User object because we can only reference the Last Login Date in Flow Builder but not in the formula field. So instead of evaluating the last login date in Choose Object and Filter Conditions, we will use a Decision element to do so.

This means, whenever the flow runs, all active users will be included in the flow. Thus, I will recommend running this flow weekly instead. Of course if you believe your instance has enough capacity and you don’t have too many users, you can still run this daily.

Flow Chart (deactivate last login date)

Steps (deactivate last login date)

Schedule-Triggered FlowGet RecordsUpdate RecordsAssignment
FormulaFormulaDecision

Does the solution solve your problem? If not, write us what your problem is and we will build the flow for you!

Official Salesforce Help Article On Flow

Subscribe
Notify of
guest

21 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Gustavo Seluja

Melody: you nailed it. Beautiful. I tested it today. Thank you!!!!!!

Users inactivated with a flow.jpg
KikaK

Hi Gustavo,

I’ve just tried to do the same for user who haven’t logged in over 90 days, but it only updated 1 user :/

Afshar

Hi Melody,

I tried replicating the steps you provided but it didn’t work for me.
I got the following error: Failed to update records whose IDs are in {!$Record}.

I’d appreciate your help.

Here are the screenshots:
https://picd.in/IqJ7kfFm
https://picd.in/sBJ0VuwB
https://picd.in/onSTaraL
https://picd.in/NS2E4DqT
https://picd.in/CAUbY6pN
https://picd.in/bA9yYwz8
https://picd.in/IpT8dEil

Thanks!

Screen Shot 2021-07-27 at 12.19.22 PM.png
Afshar

Thank you so much for replying.

Although, this time states as completed I still got the same error regarding the login date null.

Skipped this outcome because its conditions weren’t met: Last_Login_90_days_ago.

https://picd.in/c1X2N8h7
https://picd.in/rjRkqZS4

Screen Shot 2021-07-28 at 1.10.09 AM.png
Al Eric

No chance, I tried different methods and now I got UNABLE_TO_LOCK_ROW error. I checked Google but it seems too advanced for me. How can I resolve that issue? It didn’t work for me.

Al Eric

Hmm, there might be but now I get this error:

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: SendEmailForSalesRepsUserTrigger: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject Trigger.SendEmailForSalesRepsUserTrigger: line 5, column 1. You can look up ExceptionCode value

Soham

Hi Melody,

This works like a charm. Thank you for this. Only one thing I would point out is if someone has to do it on thousands of Users (e.g. Customers, Partners Profile Users), it would be better to deactivate the Users which are already beyond the threshold limit of 60/90 days and then schedule this Flow so that there would be less load the first time itself as the number of Users on which the flow has to run would be greatly reduced.

Regards,
Soham

Pavan Mundharre

Hi Melody

this is amazing

consider following scenario

  1. User A is Inactive today holding some records
  2. User A has a manager assigned

Can we following this using flow

  1. run a scheduled flow to check inactive user and their manager
  2. if user holding any record it must transfer to its manager

also

  1. run a scheduled flow to check inactive user without any manager assigned
  2. skip this user from our work

Is it possible using FLOW

James Bengel

I’ve not done much with Schedule Triggered flows, so there may be things going on that I’m not aware of that would answer these questions, but I see two things that make me pause.

  1. I’m assuming that the body of the flow is a loop operating on every active user that wasn’t filtered out by the conditions in the start element. If that’s the case, then it makes me think the Update Records is actually inside the “loop”, and not bulkified.
  2. If I were doing something like this in a different kind of flow, I’d use a Get Records to filter down to the narrowest sample of records I could — which would let me filter using the Ninety_Days_Ago formula as filter criteria.

There may be a reason that this won’t work, but it seems like it would make the flow significantly more performant, and less likely to run up against a system limit. (Our org isn’t likely to have enough inactive users to cause that problem, but a large org with a large number of users certainly could.)

So what am I missing?

Bryan Collins

On step 4, how could logic be added to ignore users that have been created in the last 90 days and have profile names that include words like community, integration, or security?

Doug Contaoi

Hi Melody! Thanks for this flow and it was helpful in my case. Question associated with the flow: let’s say I want to add a condition to only have a specific profile to evaluate, how can we reference the profile name for that? I can see that we can use ProfileId as a criteria but not best practice to hardcode IDs. What’s your recommendation? (ex I want to use the Customer Community Plus as a condition when the flow starts). Appreciate your time and effort sharing Flow knowledge!

Arthur Montes

Hello, I’m trying to add a new condition on this flow, I would like to deactivate inactive users that last login date X and uses Salesforce licence AND can not be Profile ‘System Administrator’ but till now i don’t know how to set this using $User. Glad for your attention

Qba2312

Hi Melody,
I have problem :/ I created this flow, but always this flow get only one User (always the same) and only this one user is considering to deactive. Then the flow is finished. How can I fix it to iterate for all Users?

Last edited 1 year ago by Qba2312
David

Hi Melody – running into an error after building this flow:

The flow tried to update these records: {record.id}. This error occurred: FIELD_INTEGRITY_EXCEPTION: To self-deactivate, the org must enable the user self-deactivation setting and the usertype must be external.: Active. 

This error implies it can’t be run on internal users, only portal users. Any thoughts on this?

Thanks,
-David