In our org we have several objects where the names for their records are controlled by processes (Visual Flow or Process Builder + Visual Flow).
So as I’ve been humming along writing flows I’ve starting to discover that I’ve got multiple subflows to handle the record names.
Today I’m working on consolidating several of these name-setting flows into one flow to manage them all.
Allow an Input of One or More Collections of Records
The first thing I’m going to do is setup several sObject collection variables to receive collections from calling flows:
Check Each Collection for Records
Now I’m going create a string of decision elements to check each collection for records.
If records exist, then loop through them, otherwise move on. And at the end of each loop, go to the next decision element.
Write Formulas That Can Be Used For Every Object
For every object I have two name fields to update: the standard Name field and a custom alpha-order name field. Each name string has essentially three parts: the first part identifies the client or person, the middle part identifies a product type, and the third part is a date range.
- Sample Names:
- Firstname Lastname LOC 05/2014 to 06/2015
- Client LOC 05/2104 to 06/2015
- Sample Alpha-Order Names:
- Lastname, Firstname LOC 2014/05 to 2015/06
- Client Vendor LOC 2014/05 to 2015/06
To keep the number of formulas to a minimum, which also helps with making updates later on down the road, I’m going to create two general formulas that combine the three parts of the name. Those formulas are going to use variables only, as opposed to using field references. This will allow them to be used to update records for any object.
Formulas to Create Names
Create Additional Variables and Formulas as Needed
If I was able to use field values exactly as they are in my final formula variables, then I’d be all ready to put the rest of the flow together. I’d just need to assign the fields to my Beginning, Mid and Final variables, then use the create-name formulas to populate the name fields on the records.
But you might find, as I did in my case, that you’ll need to create a preliminary layer of variables and formulas. That’s perfectly alright, just keep focusing on making formulas that can be used across the board, which means that your formulas will always use variables, and those variables will be populated either with field values, or with calculated values.
For instance, the final string is a date range. I start by assigning the dates from the record to two variables (StartDate and EndDate). Next I’ve created formulas that will extract the parts of the dates that I want:
Finally, I put all the parts of the dates together into my two final strings.
Loop Through Records
Now I’ll loop through the records for each object, placing field values into variables, then formulas into variables, then finally my formulas that create the new names into the record loop variable (it sounds more complicated that it really is). Here is the process for the date fields that are used for the final part of the record names:
Update Loop Variable and Output Collection
The last step is to update the loop variable fields and then add the loop variable to the output collection.
Final Loop Logic
How To Use This Flow
To use the subflow, the calling flow will pass one or more collections in, then receive updated collections back. Once the updated collections have been received, the calling flow can then do a Fast Update to save the changes to the database.
My Final Flow that Manages Names for Five Objects
The final flow uses the exact same logic for four different object. One of the objects has just a little simpler naming convention, so I have an abbreviated process in place for those records.
Nice! I now have just one place to go if I ever need to change the syntax of the names for these objects!