Salesforce関連の記事を書いています。

  1. Salesforce

How to loop a specified number of times in a flow|Creating a specified number of records

A very useful element in the Salesforce flow is what I personally consider to be the “loop”. This loop is an essential element when performing any kind of processing on the records stored in a collection variable.

As mentioned above, the loop function basically determines the number of times it will loop depending on the number of records in the collection variable. Therefore, it is basically impossible to loop an arbitrary number of times. However, in some cases, you may want to loop for a specified number of times.

For example, suppose you have several users who make a phone call every day. They are required to make a maximum of 10 calls per day and enter the results of those calls into Salesforce. In such a case, Salesforce would need to create 10 records daily for each user and have them enter the results of their calls for the day. In this case, we would like to use a loop to generate 10 records, but how can we create a specified number of records (10 in this case)? In this article, we would like to explain how to do this.

Flow Overview

Creating the flow this time starts with acquiring the user ID of the person to call. This also uses a loop, but you should be able to do this with no problem at all by utilizing the knowledge you have acquired so far. We will create a scheduled flow that starts at 0:00 every day.

The problem starts here. After acquiring user IDs of people to be called in the loop with collection variables, we need to create 10 records for each user to input the results of telephone calls. This is done by looping and creating a record for each person, so we can achieve the requirement by looping 10 times to create a record for each user.

To loop a specified number of times, we use “decision elements”. The maximum number of times to loop is set in the decision element, and if more than that number is entered, the loop can be terminated by moving to a different branch. More specifically, the number of times the loop has looped can be stored in a numeric variable, and if the numeric variable contains no more than 10 records, the loop can be set to run for a specified number of times, and if the number exceeds 10, the loop is terminated.

The problem here is how to get back to the determinant again after creating a record. To solve this, we can use the “connect to element” feature of the flow. This “connect to element” feature allows you to connect to the next element you wish to process once the specified process is complete. (This will be explained in more detail later.)

Obtaining the user ID to call

First, let’s create a process that uses a loop to store the user ID of the person to call in a collection variable. As shown in the figure below, we will acquire the conditions of the user to call, store the user ID in a text variable, and then store them one by one in the collection variable.

Create 10 records for each user.

Next, we loop through the collection variables in which the user IDs are stored. The first element is “reset,” which resets the numeric variable to “0. This is a numeric variable to remember how many times it has been looped.

After that, a decision element is placed to determine if the numerical variable is less than 10, and a branch is executed. If it is less than 10, it moves to the left to create a record and store it in the collection variable.

Remember to store the corresponding user ID in the record owner of the single record variable. Add that single record variable to the collection variable.

Then increment the numeric variable (counter) mentioned above by 1 in the last element.

As a reminder, the formula for “CounterIncrement” is shown below.

And here is the most important point: click the plus button under the “Counter 1” element and select “Connect to Element”.

You will then be able to select each element, and click on the “Decision Element” as explained earlier.

In this way, the iteration of incrementing the counter variable by 1 and then back to the decision element again will be executed until the number of the counter variable reaches 9.

As a result, when the counter number reaches 9, the right-hand branch is entered at the decision element, the processing for that user is complete, and the next user is processed as the target of the loop. The counter is then reset to zero and the process repeats itself.

Finally, a new record is created using the new collection variable to be created, and the process is complete.

Salesforce recent post

  1. What are Salesforce input rules? Explanation …

  2. You must be using Office365 (Microsoft365) to…

  3. How to loop a specified number of times in a …

  4. How to create an item that only the record ow…

  5. How to have Salesforce automatically enter to…

関連記事

PAGE TOP