Even though an Assignment element can be used to populate a large number of variables or fields, it may not always be a good idea to stuff them all into one.
But why use multiple Assignment elements when you can get by with fewer? The main reason is it gives you the ability to quickly read your flow and know what happening at each step of the way, but there is also an offshoot benefit.
Example of Using Multiple Assignment Elements
Here is an example where I’ve used multiple Assignment elements.
Now in actuality I could have put all the assignments into one or two Assignment elements, however, when I came back to the flow after some time has elapsed, I would not be able to easily “read” the flow to know what it was doing.
But even though I’m using multiple elements, that doesn’t mean that each element is updating a single variable or field. Instead I’m grouping the items into logical groups, and using an Assignment element for each group.
Offshoot Benefit of Using Multiple Assignment Elements
The offshoot benefits of using separate Assignment elements is that when you’re writing a flow with multiple logic branches and the process differs slightly from one branch to another, you can create one element, and then copy it for the different processes.
When doing this I recommend starting with the branch of your process that will have the greatest number of assignments, then move to the branch with the next fewer number of assignments, and so on.
This way after you copy your elements for the next branch you can very quickly and easily to pare down the assignments within the element by deleting the ones you don’t need. Deleting an assignment is much quicker and easier than adding a new one, it’s just one click on the trash can (versus two variable/value lookups and the selection of an operator).
Additionally, not only does it take a little time for the Cloud Flow Designer to locate your variables and fields each time you need to populate a variable or value input box, but each time you are grabbing resources you’re introducing an opportunity for a bug to crop up by mistakenly grabbing the wrong one. Trust me on this, it happens, and it will drive you crazy working out these bugs.
Here is an example of what I mean: Let’s say I have records from two different objects that I’ve called “HHERecs” and “MERecs”. Both of these objects have “StartDate” fields. If I enter “StartDate” into an input field, the Cloud Flow Designer will bring up a list of everything that matches that, which will include “HHERecs.StartDate” and “MERecs.StartDate”.
Now if you’re impatient, like I can be, you don’t really want to wait several seconds for the Cloud Flow Designer to finish creating its list of matching items, so you click on the list as soon as you see “StartDate” then move on to the next thing in your flow.
What you didn’t notice, however, is that you needed “MERecs.StartDate”, but you got “HHERecs.StartDate”. Boo.
So learn by my mistakes…create your most complex Assignment element first, then pare it down as you move to the branches of your process that require a simpler element.
Links to Other Flow Organization Tips:
- Grouping Flow Elements
- Labeling Flow Areas
- Moving Multiple Elements
- Reducing Number of Long Arrows
- Using Multiple Assignments