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.

#### Constants and 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.

#### Formulas:

There is only one 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:

### Putting it All Together – How the Flow Works

So here is how the CreateTempID flow works:

- The flow receives a number into its input variable “RandomNum”
- The “Seed” variable is assigned the value of that number and then the seed is passed into the random number generator
- 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.
- A “TempID” variable is appended with the NextChar
- A counter is incremented and checked against the total length of the ID
- 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!