SalesForce Flow and loop element

New flow builder is a tool of future. It allows people who are not trained or educated ( or just are not familiar with ) coding, create fully working logic without writing single line of code! Even though it has been made to be as simple as possible, there are some matters similar like in regular programmatic languages that one aware of can work faster and more efficient with flow builder. Recently I happened to watch one of my employees ( who is just getting acquaintanced with flow builder ) struggling to understand why flow is working the way it was. 

To not make you go through all of details of task let’s just simplify it to this:

We want to build a flow which updates address of every account provided to it to empty string. 

Fig. 1 Flow structure

So as simple as it is (Fig. 1), it was not doing what my friend anticipated. The problem was that records were never updated. What is more when I fixed it for him the flow looked almost the same, which didn’t make it easier for him. So the devil is in understanding how “Loop” element is working on provided data. 

The “Loop” element is doing two things ( yep it is that simple ):

  1. Take provided list and take one record from it ( the list is sorted so it will take always next element ).
  2. Make a copy of it and put it into variable provided as holder of the record.

Fig. 2 Edit Loop screen

Now I want you to focus on word copy, which I even bolded. What it means is that record that Loop element placed in variable provided to it as Loop Variable ( look at fig. 3 bottom of screen shoot ), is really a copy and any change made on it will not be moved to our collection. So “what changes do we need to make to make a change in our records?” one might ask. 

The answer is that you need to assign changes you made to new collection variable. What we made is, we did add one more assignment and created one more record variable and one more collection variable. The process was that we first assigned loop variable to new record variable, made change on it and add the variable to new collection variable, which in the end has been provided to update element. 

Fig. 3 Flow after fix

So as I written before flow almost not changed. The process is:

  1. Flow is getting list of accounts to update.
  2. The list is processed by loop element provided one record by one to two assignment elements. 
  3. First assign element takes Id of acc record from loop variable and assign it to new record variable we called “HoldingVariable” in this example. It also assign value empty string to address field of account ( that is also done to HoldingVariable ).
  4. Second assign element is adding record we created in HoldingVariable to new collection which will be later used to update.

Below i provide screenshots of assign elements just in case of any questions 😉 

Fig. 4 first assign element

Fig. 5 second assign element

Leave a comment

Your email address will not be published. Required fields are marked *