Loading

Fetching Account Records for Current Month Initiated

Дата публикации: Aug 25, 2025
Описание

In Salesforce, retrieving records is often achieved through the "Get Record" element within a flow. However, in some cases, more intricate methods are necessary. For example, there could be a requirement to retrieve records based on specific criteria or to perform the task only on certain scheduled days.

Our solution caters to these requirements by orchestrating record retrieval for the current month and executing actions exclusively on designated days. This guarantees both the timeliness of the retrieved data and compliance with predefined operational schedules.

Решение

In this help article, We'll detail the process of executing a Schedule-Triggered Flow in Salesforce, Designed to run on the 7th day of each month. The Flow objective is to retrieve records with start dates falling within the same month and year as the current date, and subsequently update these records by adding 12 months to their start dates.

Our Flow meticulously verifies the current date to ensure it matches the scheduled execution day. Once confirmed, It systematically fetches all account records categorized as Customer Type and initiated within the ongoing month.

Upon successful retrieval, The Flow proceeds to update the start date of each retrieved account record, Extending it by 12 months. This adjustment ensures that the records accurately reflect the appropriate timeframe for future reference and planning.

The breakdown of the Flow which we created is as follows :

Step 1: Create a Start Date field

  • Create a new field named Start Date with the Data type Date by navigating to Setup > Object Manager > Account > Fields and Relationships

Step 2: Create a Flow

  • Click Setup
  • Search for the Flows on the Quick Find, And click Flows
  • On the Flow Screen click New Flow
  • Select the Scheduled Trigger Flow from the Flow Types and Click Create
  • Set the appropriate Start Date and Time to run the Flow

Step 3: Create a Formula that checks if the current day matches a specified day

  • Add a new Formula resource
  • Select Formula as the resource type
  • Set the return Data Type to Boolean
  • Write the Formula to check if the current day matches the specified day, Such as checking if today is the 7th of the month DAY(TODAY()) = 7

 

a.png

Step 4: Drag and drop a Decision Element onto the canvas 

  • Configure the Decision Element to evaluate if today is the specified day using the Formula created above
  • Set the Decision Element to take the Yes path if the Formula returns True

b.png

 

Step 5: Then, Add a Get Records element to the Flow

  • Configure the Get Records element to retrieve records of the Account object
  • Specify the condition that the Type of the Account must be Customer to filter the records accordingly

c.png

 

Step 6: Create a loop in the Flow to iterate through the collection of Account records retrieved

 

 

Step 7: For each record, create a Formula to check if the Start Date falls within the same month and year

  • Configure the Formula to return true if the Start Date has the same month and year as the current month and year
MONTH({!Loop_through_Account_Records.Start_Date__c}) = MONTH(TODAY()) && YEAR({!Loop_through_Account_Records.Start_Date__c}) = YEAR(TODAY())

d.png

Step 8: Set the Decision Element to take the Yes path if the Formula returns True

e.png

Step 9: Now create a collection variable of type Record that will hold the accounts with the same month and year

  • Click on New Resource
  • Choose the Resource type as Variable
  • Select the Data Type as Record
  • Set the Checkbox  Allow multiple values (collection) to True
  • Choose Account as the object for the Variable
  • Checkbox Available for Input/output to True

f.png

Step 10: In the Yes path of the Decision Element, Add an Assignment Element to the Flow

  • Configure the Assignment Element to add the Account records that have matched the criteria the same month and year for the Start Date to the collection variable created above

g.png

 

Step 11: Add a Loop element to the Flow canvas

  • Configure the Loop to iterate through the Collection Variable created to store accounts of the same month and year

 

h.png

Step 12: Create a record variable to store the current Account record from the loop

  • Click on New Resource
  • Choose Variable as the Resource Type
  • Select Record as the Data Type
  • Specify the object as Account

i.png

Step 13: Create a Formula resource for adding 12 months to a Start Date

  • Click on New Resource
  • Choose Formula as the Resource type
  • Set the return Data type based on the Data type of the Start Date field (twe are setting Date here)
  • Write the Formula to add 12 months to the Start Date. Depending on the requirements, the Formula may vary
ADDMONTHS({!Loop_Through_List_of_Accounts.Start_Date__c},12)

 

j.png

Step 14: In the loops for each branch, add an Assignment element

  • Assign the current account record from the loop to the record variable created in step 12
  • Use the Formula resource created earlier to calculate the updated Start Date
  • Assign the updated Start Date to the Start Date field of the record variable

Step 15: Create a collection variable of type Record that will hold the accounts that needs to be updated

  • Choose the Resource type as Variable
  • Select the Data type as Record
  • Set the Checkbox Allow multiple values (collection) to True
  • Choose Account as the object for the Variable

l.png

Step 16: Under the Assignment element added in the Step 15, add another Assignment element

  • Configure it to add the record variable, which adds the updated account record, The collection variable created earlier to store the accounts to be updated

 

Step 17: Outside the loop, add an Update Records element to the Flow canvas

  • Configure it to choose the option Use the IDs and all field values from a record or record collection
  • Select the Record or Record Collection variable created earlier, Which stores the accounts that need to be updated

 

  •  Save and Activate the Flow

 

Testing :

  • Create a Account record
  • Enter Account Name that you want
  • Choose Customer-Direct as Type and click on Save

Result :

 

_________________________________________________________________

Written by: Maham Hassan | Forum Ambassador

Maham Hassan is 2x Mom, Salesforce MVP, Director & Technical Architect @ Cloud-1 & Check Automate, Founder of Dubai Dreamin, 16x Certified, Trailblazer Mentor, Community Group Leader & All Star Ranger. 

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

Номер статьи базы знаний

001979869

 
Загрузка
Salesforce Help | Article