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.
In this article, we will see how to achieve this requirement.
Note:
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
Step 2: From the Quick Find box, search for Flows and select the New Flow button
Step 3: Select Schedule-Triggered Flow and hit the Create button
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
To have the scheduled Flow running, we have to specify the object and the conditions that each record must meet. Provide the following values
| Object | Account |
| Condition Requirements | All Conditions Are Met (AND) |
| Logic | Is_Active__c Equals {!$GlobalConstant.True} |
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) |
| Object | Opportunity |
| Condition Requirements | All Conditions Are Met (AND) |
| Logic | AccountId Equals {!$Record.Id} |
| Sort Order | Descending |
| Sort By | CloseDate |
| How Many Records to Store | Only the first record |
| How to Store Record Data | Automatically store all fields |
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 Type | Formula |
| 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 Type | Number |
| Decimal Places | 0 |
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)
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) |
| Label | No |
| Condition Requirements | All Conditions Are Met (AND) |
| Logic | {!Get_Opportunity.Id} Is Null {!$GlobalConstant.False} AND {!Formula_MonthsDifference} Greater Than or Equal 6 |
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 Values | Use the account $Record global variable |
| Condition Requirements | None-Always Update Record |
| Set Field Values for the Account Record | Is_Active__c = False |
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)
Step 10: Finally, click on the Activate button available next to the Save button to activate the Flow
_____________________________________________
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
001328491

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.