Last Updated on January 1, 2021 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 Flow
- Use Process Builder to automate freezing a user
- Launch a Flow from Process Builder
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):
We will use Process Builder and Flow to solve the above business requirement in order to keep it scalable and declarative.
Before proceeding, you may want to follow this link: UserLogin to help you understand the UserLogin object.
Before discussing it, 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 3 steps to solve Steven’s business requirement using Flow and Process Builder. We must:
- Create a custom date field (Freeze Date) on the user object
- Lightning Flow Steps:
- Define flow properties for auto-launched flow
- And add text variable to store User Id
- Add an update records element – update IsFrozen to true
- Process Builder Steps:
- Define process properties
- Define evaluation criteria
- Define process criteria
- Set time for actions to execute
- Add action – flows
- Add action – update records
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: Lightning Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flows.
- Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- It opens ups the Flow Designer for you.
Step 2.2: Lightning Flow – Add Text Variable to Store User Id
Now create a Text variable varTUserId to store the user’s Id, which we will later pass through from Process Builder.
- Under Toolbox, select Manager, then click New Resource to store user record.
- Input the following information:
- Resource Type: Variable
- API Name: varTUserId
- Data Type: Text
- Default Value: {!$GlobalConstant.EmptyString}
- Check Available for Input
- Check Available for Output
- Click Done.
Step 2.3: Lightning 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.
- Under Toolbox, select Element.
- Drag-and-drop Update Records element onto the Flow designer.
- Enter a name in the Label field; the API Name will auto-populate.
- Click 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: {!varTUserId}
- Row 1:
- Set Field Values for the User Login Records
- Row 1:
- Field: IsFrozen
- Value: {!$GlobalConstant.True}
- 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.
- API Version for Running the Flow: 50
- Interview Label: Freeze user account flow {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Our next task is to create a Process on the User object to Launch a Flow, only when a Freeze Date is not null. To create a Process on the User object, follow the instructions below.
Step 3.1: Define Process Properties
- Click Setup.
- In the Quick Find box, type Process Builder.
- Select Process Builder, then click New.
- Name the Process and click the Tab button. The API Name will populate.
- As a best practice, always input a description.
- The process starts when A record changes.
- Click Save.
Step 3.2: Define Evaluation Criteria
- Click on the Add Object node to begin selecting the evaluation criteria.
- Select the User object from the dropdown list.
- Start the process when a record is created or edited.
- Click Save.
Step 3.3: Define Process Criteria
- Click the Add Criteria node to begin defining the process criteria.
- Name the criteria.
- The criteria should execute actions when the conditions are met.
- Set Conditions
- Row 1
- Field: User | Freeze Date
- Operator: Is Null
- Type: Boolean
- Value: False
- Row 1
- Select All of the conditions are met (AND).
- Click Advanced.
- Select Yes to execute the actions only when specified changes are made to the record.
- Click Save.
The reason why we would select the Yes checkbox for the question — Do you want to execute the actions only when specified changes are made to the record? — is to allow the Process Builder to execute the actions only if the record meets the criteria now, but the values that the record had immediately before it was saved didn’t meet the criteria. This means that these actions won’t be executed when irrelevant changes are made.
Step 3.4: Set time for actions to execute
The next step is to set the time for scheduled action.
- Below Scheduled Actions, click Set Schedule.
- Set Field Values:
- Row 1:
- 0
- Hours
- After
- Freeze_Date__c
- Row 1:
- Click Save.
Step 3.5: Add Action – Flows
Now we have to add the Action into the Process to launch a Flow.
- Below 0 Hours After Freeze_Date__c Scheduled Actions, click Add Action.
- For Action Type, select Flows.
- Name the action.
- Select the flow we just created – Freeze user account flow.
- Set Flow Variables:
- Row 1:
- Flow Variable: varTUserId
- Type: Field Reference
- Value: User | Id
- Row 1:
- Click Save.
Step 3.6: Add Action – Update Records to Set Freeze Date to Null
Add another action to clear the Freeze Date field.
- Below Scheduled Actions, click Add Action.
- For Action Type, select Update Records.
- Name the action.
- Select the option Select a User related that started your process for the record type.
- The criteria for updating records should be No criteria-just update the records!.
- Set new field values for the records you update:
- Row 1:
- Field: Freeze Date
- Type: Global Constant
- Value: $GlobalConstant.Null
- Row 1:
- Click Save.
In the end, Warren’s Process will look like the following screenshot:
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
Now onwards, if a system administrator or anyone set the Freeze date for a user.
Process Builder will fire on that day 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?
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.
16 thoughts on “Getting Started with Process Builder – Part 28 (Auto Freeze Users Account)”
Prasad Shiraskar
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?
Rakesh Gupta
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
Prasad Shiraskar
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
Rakesh Gupta
I would suggest using Debug log to find the root cause. Also check if, process builder is able to find the user.
sagarbtech50
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
Rakesh Gupta
As per my knowledge No
Sagar K
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
Rakesh Gupta
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
sagarbtech50
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
Rakesh Gupta
Check out this thread (https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000009OEk&fId=0D53000002E7Ei0) on Success Community.
Sagar K
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
Rakesh Gupta
Yes you can achieve it thorough Process Builder and Flow. What specific error you are getting ?
Sagar K
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’
Rakesh Gupta
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.
Samir Sayyad
Hi Rakesh,
Malware issue in Remedyforce: Everyday 5-6 user’s accounts are getting frozen. Appreciate if we get solution to this ASAP.
Thanks.
Rakesh Gupta
Malware ?? Could you please explain me your requirement in detail