Loading

How to Automatically Deactivate Accounts Having Inactive Opportunities Using Salesforce Flow

Date de publication: Apr 2, 2026
Description

An organization is looking for an automated solution to automatically mark an Account record as inactive if the latest related Opportunity record's Close Date has passed more than 6 months.

Résolution

In this article, we will see how to achieve this requirement. 

 

Note:

  1. In this scenario, we are assuming that there is a custom checkbox field Is Active (API Name: Is_Active__c) on the Account object to denote whether the Account record is active or not.
  2. Make sure the Default Workflow User is set in the org for scheduled flows. Checkout this article to learn how to set the Default Workflow User: https://help.salesforce.com/s/articleView?id=sf.workflow_defaultuser.htm&type=5

 

As this automation has to run daily at a particular time duration, we will use Scheduled-Triggered Flow. Follow the steps provided below to create the automation:


Step 1: Login to your Salesforce account. Click the Gear Icon on the top right corner of your screen and select Setup

 

08.png

 

Step 2: From the Quick Find box, search for Flows and select the New Flow button

 

09.png

 

Step 3: Select Schedule-Triggered Flow and hit the Create button

 

10.png

 

Step 4: In the Flow canvas, set up the schedule for the Flow to run by substituting the values of Start Date, Start Time and frequency (set frequency to Daily). Set the Start Date to today's date if you are planning to start the automation to work from today otherwise set the date in future whenever you are planning to set the schedule to start running. For the Start Time, assign the value according to your requirement

 

11.png

 

To have the scheduled Flow running, we have to specify the object and the conditions that each record must meet. Provide the following values

ObjectAccount
Condition RequirementsAll Conditions Are Met (AND)
LogicIs_Active__c    Equals    {!$GlobalConstant.True}

 

 

12.png

 

Step 5: Add a Get Records Element available under Interaction section when the + icon is selected

In the Get Records Element, substitute the following values:

Label

Get Opportunity

(Note: Provide any suitable name)

Description

(Provide any suitable description) 

(Note: It's optional but it's a best practice to provide descriptions)

ObjectOpportunity
Condition RequirementsAll Conditions Are Met (AND)
Logic AccountId Equals {!$Record.Id}
Sort OrderDescending
Sort ByCloseDate
How Many Records to StoreOnly the first record
How to Store Record DataAutomatically store all fields

 

13.png

 

Step 6: Create a new Formula Resource Type for calculating the Difference in Months between Close Date and Current Date of the running Flow

Substitute the values as follows:

Resource TypeFormula
API Name

Formula_MonthsDifference

(Note: Provide any suitable API name for the formula)

Description

(Provide a suitable description)

(Note: It's optional but it's a best practice to provide description)

Date TypeNumber
Decimal Places0

 

Formula:

(MONTH({!$Flow.CurrentDate})+(YEAR({!$Flow.CurrentDate})-YEAR({!Get_Opportunity.CloseDate}))*12-MONTH({!Get_Opportunity.CloseDate}))-
IF(ADDMONTHS({!Get_Opportunity.CloseDate},MONTH({!$Flow.CurrentDate})+(YEAR({!$Flow.CurrentDate})-YEAR({!Get_Opportunity.CloseDate}))*12-MONTH({!Get_Opportunity.CloseDate}))>{!$Flow.CurrentDate},1,0)

 

 

14.jpg 

 

Step 7: Once the Formula is created, we will reference this in the Decision Element for checking if the Get Opportunity is Null or not and if the latest opportunity Close Date has exceeded 6 months or not.


Create a Decision Element as follows:

Label

Check if the Get Opportunity is Null

(Note: Provide any suitable name)

Description

(Provide any suitable description)

(Note: It's optional but it's a best practice to provide descriptions)

LabelNo
Condition Requirements All Conditions Are Met (AND)      
Logic{!Get_Opportunity.Id}    Is Null    {!$GlobalConstant.False}
AND
{!Formula_MonthsDifference}    Greater Than or Equal    6

 

 

15.jpg

 

 

Step 8: Under the branch where the Get Opportunity is found and the latest Opportunity's Close Date has exceeded 6 months criteria is satisfied, we will add an Update Records Element to update the Is Active checkbox on the Account record as False to denote that the Account is now inactive

 

In the Update Records Element, substitute the following values:

Label

Update Account record

(Note: Provide any suitable name)

Description

(Provide any suitable description)

(Note: It's optional but it's a best practice to provide descriptions)

How to Find Records to Update and Set Their ValuesUse the account $Record global variable
Condition RequirementsNone-Always Update Record
Set Field Values for the Account RecordIs_Active__c = False

 

17.jpg

 

Step 9: Now, on the upper right side of Flow canvas, hit the Save button and provide a suitable Flow Label (It is a best practice to provide descriptions)

 

18.png 

 

Step 10: Finally, click on the Activate button available next to the Save button to activate the Flow

 

19.png

_____________________________________________

Written by: 
Ajaypreet Singh Saini | Forum Ambassador
Ajaypreet Singh Saini is working as a Salesforce Implementation Specialist at Grantbook. Prior to Grantbook, Ajaypreet served as a Salesforce Administrator for 2 years working on Sales Cloud where he was responsible for configuring and administrating complex processes and maintaining security of Salesforce Instance.


Submissions reflect only the opinions of the user who made available the Submission and not the opinions of Salesforce, regardless of whether the user is affiliated with Salesforce, and may contain or constitute products, services, information, data, content and other materials made available by or on behalf of third parties ("Third Party Materials).  Salesforce neither controls nor endorses, nor is Salesforce responsible for, any Third  Party Materials, including their accuracy, validity, timeliness, completeness, reliability, integrity, quality, legality,  usefulness or safety, or any applicable intellectual property rights. Any Submissions made available through any message board or forum in response to posted questions, or that otherwise purports to answer any questions, including any questions about Salesforce or Programs, are made available for your general knowledge only and should never be relied upon as answers to your specific questions (even if an answer is marked as a “best” answer or with any similar qualifications). You should always contact Salesforce support for answers to your specific questions. Salesforce has no control over Submissions, and is not responsible for any use or misuse (including any distribution) by any third party of Submissions.

If you have questions, tap into the wisdom of our entire Trailblazer Community here: https://trailhead.salesforce.com/trailblazer-community/feed

Numéro d’article de la base de connaissances

001328491

 
Chargement
Salesforce Help | Article