RSS

One Flow to Manage Fields on Many Objects

21 Nov
One Flow to Manage Fields on Many Objects

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.


The Strategy

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:

Input Collection Variables

Input Collection Variables


Check Each Collection for Records

Now I’m going create a string of decision elements to check each collection for records.

Decision Element String

Decision Element String

.

If records exist, then loop through them, otherwise move on. And at the end of each loop, go to the next decision element.

Decision Element String with Loops

Decision Element String with Loops


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

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:

  • GetStartMonthString
  • GetStartYearString
  • GetEndMonthString
  • GetEndYearString

Finally, I put all the parts of the dates together into my two final strings.

Formulas for Final String

Formulas for Final String


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:

Assign Dates to Variables

Assign Dates to Variables

Assign Formulas to Variables

Assign Formulas to Variables

Assign Final String Variables

Assign Final String Variables


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.

Update Loop Variable Fields

Update Loop Variable Fields

Add Loop Variable to Output Collection

Add Loop Variable to Output Collection


Final Loop Logic

Final Loop Logic

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.

Final Flow

Final Flow


Nice! I now have just one place to go if I ever need to change the syntax of the names for these objects!

Advertisements
 
1 Comment

Posted by on November 21, 2015 in Visual Flow

 

Tags: ,

One response to “One Flow to Manage Fields on Many Objects

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: