Last Updated on April 8, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
There are a few situations where the user account requires more work before deactivating it. To prevent users from logging into the organization while you perform the steps to deactivate them, you can freeze user accounts. To freeze a user account, you have to navigate to the user record and then click on the Freeze button.
Objectives:
After reading this blog post, the reader will be able to:
- Create a custom field
- Use Schedule-Triggered Flow to automate freezing a user
- Monitor Schedule job flow queue
Business Use case
Steven Greene is working as a System administrator in Universal Container. He received a new requirement to automate the user freeze process. They want to allow their system administrators or delegated administrators to enter a user’s account freeze date and the system will auto-freeze the user account on that day.
Automation Champion Approach (I-do):
While this can be solved using various automation tools like Apex, etc, we will use Scheduled-Triggered Flow.
Before proceeding ahead, you have to understand the UserLogin object. Represents the settings that affect a user’s ability to log into an organization.
Before discussing the solution, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.
Guided Practice (We-do):
There are 2 steps to solve Brenda’s business requirement using Scheduled-Triggered Flow.
- Create a custom date field (Freeze Date) on the user object
- Salesforce Flow Steps:
- Define flow properties for scheduled-triggered flow
- Add a decision element to check if freeze date is less or equal to today
- Add an update records element to update the isFrozen=True
- Add an update records element to wipe-out value from Freeze Date field
Step 1: Creating a Custom Date Field on User Object
- Click Setup.
- In the Object Manager, type User.
- Select Fields & Relationships, then click New.
- Select Date as Data Type, then click Next.
- Enter Field Label and click the tab key, the API Name will populate.
- As a best practice, always input a description.
- Set the Field-level Security for the profiles, make sure to set this field as read-only for everyone except system administrators or right users.
- Add this field to Page Layout.
- Click Save.
Step 2.1: Salesforce Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Schedule-Triggered Flow option and click on Create and configure the flow as follows:
- Set Conditions:
- Click Done.
Step 2.2: Salesforce Flow – Using Decision Element to Check if Freeze Date is Less or Equal to Today
Now we will use the Decision element to check, if freeze date is less or equal to today.
- On Flow Designer, click on the +icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource: {!$Record.Freeze_Date__c}
- Operator: Less Than or Equal
- Value: {!$Flow.CurrentDate}
- Row 1:
- Click Done.
Step 2.3: Salesforce Flow – Update Records to Update IsFrozen to True
The next step is to update the field IsFrozen on the UserLogin object to freeze the user’s account.
- On Flow Designer, click on the +icon and select the Update Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- For How to Find Records to Update and Set Their Values select Specify conditions to identify records, and set fields individually
- Object: User Login
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: UserId
- Operator: Equals
- Value: {!$Record.Id}
- Row 1:
- Set Field Values for the User Login Records
- Row 1:
- Field: IsFrozen
- Value: {!$GlobalConstant.True}
- Row 1:
- Click Done.
Step 2.4: Salesforce Flow – Update Records to Update Freeze Date Equal to Null
The next step is to update the field Freeze Date to Null on user object.
- On Flow Designer, click on the +icon and select the Update Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- For How to Find Records to Update and Set Their Values select Use the user $Record global variable
- Set Filter Conditions: None – Always Update Record
- Set Field Values for the User Records
- Row 1:
- Field: Freeze_Date__c
- Value:
- Row 1:
- Click Done.
In the end, Steven’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- Type: Schedule-Triggered Flow
- API Version for Running the Flow: 54
- Interview Label: Auto Freeze Users Account {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate.
Monitor Your Schedule Flow
To monitor Flows that are scheduled, navigate to the following path:
- Navigate to Setup (Gear Icon) | Environments | Jobs | Scheduled Jobs.
- Now look for your Scheduled Flow displaying information as shown in the following screenshot:
- Use the Del link to delete the Scheduled Flow job from the queue.
Proof of Concept
Every night at 12:00 AM, a scheduled job will run and start freezing the user’s account if the freeze date is less or equal to today.
- Now onwards, if a system administrator or anyone set the Freeze date for a user.
- Scheduled Flow will fire everynight and froze the user account.
Guided Practice (You-do):
Identify additional actions (like remove permission set) that should be completed when a user is frozen. Add to the Process Builder.
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.
Thanks a Lot Rakesh for te Detailed Tutorial , We enable community users through our Contact Object is there a way I can get the Freeze Date auto populated from Contact Object , than the users filling it everytime
Can this be used for password reset instead of freeze? I have a requirement to reset the password after a process builder completes a scheduled action of activating a user. Just wanted to know whats the solution and if this might work.
Yes you can but you have to use Apex. with Flow/Process Builder
I want to update all Contacts associated to Account when Status updates to Cancelled and want to disable all the community users associated with that Account’s Contacts. How can this be achieved with Process Builders and/or Flows?
Here you got, try this
Use process builder to Update Account’s Contacts when account status updates to Cancelled.
Use time-based action to deactivate user, we are using time-based action to avoid MIXED DML operation.
Good luck
Hey Rakesh,
Thanks for your prompt response. I did try as per you mentioned. Now it’s allowing me to save the account with the cancelled status without any error after I used the time based action. But it’s not updating anything on the contact and neither deactivating the status nor deactivating the community user associated with the Contact.
The Process Builder (PB) is on Account: Created or Edited — Recursion checkbox Off.
The Following Conditions are met
[Account].ParentId — Isnull — Boolean — False
[Account].Parent.PersonContactId – Isnull — Boolean — False
[Account].Parent.Status__c — Equals — Picklist — Cancelled
[Account].Parent.RecordType.DeveloperName — Equals — String — Business_Account
Do you want to execute the actions only when specified changes are made to the record? Checked
Immediate Action
No criteria—just update the records!
[Account].Parent Account ID.Contact ID
Account Status — String — Cancelled
Time Based — 1 Hour After Last Modified Date
[Account].Parent Account ID.Contact ID.Users
Active — Boolean — False
Also tried
Is Portal Enabled — False
NO Paused and Waiting Interviews
I would suggest using Debug log to find the root cause. Also check if, process builder is able to find the user.
Hello Rakesh,
I achieved it…A big thanks for your support.
Really i learnt a lot from your blogs.
I have one more question for you:
In PB in Scheduled actions if we put record update(if we make PB fired) that will come and wait in “Paused and Waiting interviews”
Now what i am trying to do is….Even though users having “Manage Force.com Flow” permission …. i don’t want them to delete waiting interviews under ‘Paused and Waiting interviews’
(OR)
Is their anyway to track who deleted waiting interviews?
Thanks in Advance,
Sagar
As per my knowledge No
yeah! able to get Scheduled jobs option now…
–Correct me if my way is wrong–
Created 2 fields( 4 hours and 8 hours) on user object with checkbox data type.
so if i edit the user record, changed the profile( to system admin), checked the 4 hours(field) and save the record.
Our aim is to revert back the profile to previous profile after 4 hours.
I started building Process Builder like below:
1. Selected USER object
2. In CRITERIA:
selected- Conditions are met
In set conditions :
Field : 4 hours (field)
Operator : equals
Type : Boolean
Value : True
Conditions: All conditions are met
Advanced: Do you want to execute the actions only when specified changes are made to the record? = TRUE
IN Scheduled Actions:
I gave 4 hours after “last modified date”
–>IN Add Action:
Selected “Update Records”.
Under RECORD took “user”
IN criteria for updating records:
selected “No criteria—just update the records!”
Could you help me to achieve this please!!!
Thanks Again
Option 1:- Try PRIORVALUE() formula
https://rakeshistom.wordpress.com/wp-admin/post.php?post=6627&action=edit
Option 2 :- Create a custom field on the user object to save the old profile id
Hi Rakesh,
–> Created new field in User object
As suggested, i have created a WFR to capture old profileID in new field
–> And in flow i created a Record update element (i am pulling old profileID value here) and i am calling this flow in Process builder in scheduled actions
its not working:-(
I have a doubt:
Which will execute first :
Workflow Rule (or) process builder as per salesforce order of execution.
The link which you shared its not opening, please check.
and i have a request for you,
why don’t you make this scenario as your next post ( i believe this typical scenario will meet your standards to post)
Thanks,
Sagar
Check out this thread (https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000009OEk&fId=0D53000002E7Ei0) on Success Community.
Hi Rakesh,
I am in love with your blog…thanks a lot:-)
but…by referencing the above article i tried to achieve a new requirement… but i am keep on failing, can you help me on this please!!!
Business requirement:
Being an Salesforce Administrator i have to give system admin access to users for 4 hours or 8 hours or 12 hours…and have to revert that access automatically after that (4 hours or 8 hours or 12 hours).
Could you let me know whether we can achieve this!!!
Thanks in Advance,
Sagar
Yes you can achieve it thorough Process Builder and Flow. What specific error you are getting ?
I selected the ‘User’ object in Process Builder
In ‘Start the process’
If we select ‘when a record is created or edited’ scheduled action tab is not appearing…(if this is not possible how can we update profile after 4 hours or after 8 hours)
Its appearing only for
‘only when a record is created’
Scheduled actions are only available in two cases.
On the object node, the process is set to “Start the process only when a record is created.” All criteria will then have the Scheduled Actions option available.
OR
On the object node, the process is set to “Start the process when a record is created or edited”, AND on the criteria node, the checkbox “Do you want to execute the actions only when specified changes are made to the record?” is checked. Only criteria on which this is checked will have the Scheduled Actions option available.
Hi Rakesh,
Malware issue in Remedyforce: Everyday 5-6 user’s accounts are getting frozen. Appreciate if we get solution to this ASAP.
Thanks.
Malware ?? Could you please explain me your requirement in detail