Auto-Deactivate Users with Schedule-Triggered Flow in Salesforce

In Salesforce user management, we cannot delete a user once it is created, so we deactivate the user account to refrain the user from having access to the organization.

We can automate the process of user deactivation using the flows, and in this Salesforce tutorial, we will learn to Auto-Deactivate Users with Schedule-Triggered Flow in Salesforce.

Create a Schedule trigger flow to deactivate Users in Salesforce

To auto-deactivate users in Salesforce, we will create a Schedule-triggered flow in the following steps.

In this schedule trigger flow, we will set conditions to deactivate the user, where if the user hasn’t logged in for the last 60 days, his account will be deactivated.

1. Navigate to the setup of Salesforce, and in the Quick Find box, search, then select Flows under the heading Process Automation.

2. In the flows setup window, click on the button New Flow.

3. Select the option Schedule-Triggered Flow, and click Create.

Deactivate Users using flow in Salesforce

4. Select the Start Date and Start time for the schedule of the trigger flow. After this, select the frequency from the options Once, Daily, and weekly.

Deactivate Users using flow in Salesforce

5. Select the Object as User. In the Condition requirements, set the Field as IsActive, Operator as Equals, and Value as True.

Deactivate Users with last login date using flow

6. Create a New Resource for the formula that we will use to find the last login date.

Enter the below details in the New Resource.

  • Enter the Resource Type as Formula.
  • Enter API Name as Last_login.
  • Select Data Type as Date Time.
  • In the Formula section, enter the formula NOW() – 60. This will subtract the current date from 60 days.
  • At last, click Done.
Automate user deactivation using flow in Salesforce

7. Add a decision element to the flow; in this, we will add the conditions for the last login date.

  • Enter the Label and the API Name for the decision element.
  • Enter the label and Outcome API name in the Outcome Details section.
  • In the Condition Requirements, select Resource as Record > Last Login, Operator as Less than or Equal, and Value as formula variable Last_login.
Use Scheduled trigger flow to deactivate user in Salesforce

9. In the decision element, add an assignment for the last login decision and enter the Label and API Name for the Assignment element.

See also  Migrate Workflows and Process Builder to Salesforce Flow

In the Variable Values, select the Variable as Record > Active, Operator as Equals, and Value as False.

Use Salesforce Flow to auto deactivate the users

10. Below the Assignment element, add an Update Record element and configure it in the following way.

  • Enter the Label and the API Name.
  • Activate the radio button ‘Use the IDs and all field values from a record or record collection.’
  • In the Record or Record User, select the option Record User, or it might appear as Triggering User.
How to auto Deactivate Users in Salesforce

11. Click on the Save button and enter the Flow Label, and the Flow API Name will be auto-filled according to the entered Flow Label; after this, click Save.

Salesforce User Deactivation using flow

12. Click on the Activate button to activate this flow.

Auto-Deactivate Users with Schedule-Triggered Flow in Salesforce

Now, the flow will be triggered on the Scheduled date and time, and according to the defined conditions in the flow, if any user hasn’t logged in for the past 60 days, his account will be deactivated.

In this way, by following the above steps, we can auto-deactivate Users with Schedule-Triggered flow in Salesforce using the last login date.

Conclusion

In Salesforce, automating user deactivation using Schedule-Triggered Flows is useful in enhancing user management efficiently. By automating the process based on specific criteria, we can ensure timely deactivation of user accounts.

By following the above steps, you might have understood the process of Auto-deactivation of Users with Schedule-trigger flow using the last login date as criteria.

You may like to read: