RSS

Create Temporary ID Subflow

21 Oct
Create Temporary ID Subflow

Have you ever needed to create a temporary ID? Well here’s a little flow that will show you how to do that.


Random Number Generator

First you’ll need a random number generator. As of this writing (October, 2015) Salesforce didn’t have a random number generator, so you’re going to have to construct one. Here is a link to my previous post on how I made a pseudo random number generator. There may be other solutions available, but none that I was able to find (yet!).


The CreateTempID Flow

Next you’ll need to construct this little Flow.

TempID Flow

Constants and Variables:

Constants & Variables

Constants & Variables

  • Constants
    • HighNum = 61, LowNum = 1, Precision = 0 (these are values used in the random number generator)
    • IDLen = 18 by default in my flow, but this could be any length you want, like 12, or 15 as long as the text field on the object where it is saved can handle its length. (See 11/2015 update below.)
  • Variables
    • Counter keeps track of the number of times through the loop
    • RandomNum, an input variable, is any number as long as it is different for each new temp ID that is being created
    • Seed is input into the random number generator, and a new seed value is received back from it
    • TempID is the ID that is returned by the flow

11/2015 Update: I found that having an ID length of 18 is a bit overkill, and can also max out the number of loop iterations that are allowed in Flow when creating several records. For this reason I’ve changed IdLen to an Input variable with a default value of 5. The calling flow can now pass in a different Id length if desired.

IdLength Input Variable

IdLength Input Variable

Formulas:

There is only one formula:

NextChar Formula

NextChar Formula

This formula is used to get translate the random number received by your generator into one of 61 different characters (plus a default character). Of course you don’t have to have 61 different characters in your formula. In fact when I started using this flow my formula had only 27 characters (A through Z) plus a default character of “0” and it worked just fine. Just be sure, if you construct your formula with fewer characters, to change your HighNum constant to match the number of characters in your formula (not including the default character).

Creation of the Temp ID:

The TempID is created in an assignment statement that adds the NextChar to its end:

Assignment Element

Assignment Element


Putting it All Together – How the Flow Works

So here is how the CreateTempID flow works:

  1. The flow receives a number into its input variable “RandomNum”
  2. The “Seed” variable is assigned the value of that number and then the seed is passed into the random number generator
  3. The random number generator returns a new random number between the lowest and highest CASE lookup items in the NextChar formula (in my formula, between 1 and 61). It also returns the next Seed number.
  4. A “TempID” variable is appended with the NextChar
  5. A counter is incremented and checked against the total length of the ID
  6. Once the total length of the ID is reached the Flow ends and passes back the TempID

Pretty cool.

Next I’ll demonstrate a use case for this little flow: linking related records on two different objects together as they are being created.

Cheers!

Advertisements
 
Leave a comment

Posted by on October 21, 2015 in Tools, Visual Flow

 

Tags: , ,

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: