Making a Dynamic Choice That Much Better


Let’s say that you are writing a flow and at one point you are going to prompt your user for some data that will then be used to populate a dynamic choice field.

Tell me hot shot, how do you handle just one single record?Do you make your user select one and then click through, or is there a better way?

Image “Can I choose not to do Matrix 2 and 3?”

Well, the good news is, you can make a smarter dynamic choice flow. By using some logic and a couple queries, you can choose to display the dynamic choice or bypass it. The reason we can do this is because instead of checking to see how many records are returned, we are just going to check to see if there is more than one. 

The example I am going to use takes a user input of “Last Name” and will check to see if there is ONE or ONE+ records and then determines if the user should see the dynamic choice page or a generic page displayed to the user.



1)      Query1 is based on the user input. ID of the first record is passed to a variable (VarID1)


2)      Query2 is based on the user input AND the ID cannot equal VARID1

3)      The results of Query2 is passed to a variable (VarID2). This variable has a default value of zero

4)      Decision point evaluates VarID2 and if the variable DOES NOT equal zero, the dynamic choice screen is presented. Default outcome (in this case) is just a display screen.


5)      Take the rest of the day off (just kidding)

I wish there was more to this, but it really is just a nice piece of logic and the fact that your user doesn’t have a click gate if there is just one record returned will probably go unnoticed, but you will know the truth!


EDIT! This blog post really covered this on a high level. If you want a blow by blow account, head over to my buddy Rakesh’s blog…


using a formula field to generate random numbers in Salesforce


In the course of getting “Project X” on the road to AMAZING I had to figure out how to get a random number out of salesforce. Since I am not a coder (Clicks not Code FTW!) I went through the formula documentation on success.salesforce and could not find anything like the excel function “random”. The google machine had suggestions, but they were all code driven. This is an interesting post as well. (

So, what’s a poor admin to do? Well, if option A doesn’t work and option B is not going to work, this admin gets out his thinking cap (Seattle Seahawks throwback, btw) and gets to work.

First, I had to think about what I was trying to do. Am I really trying to make a random number? Do random numbers exist at all? The truth is, I can give you random numbers all day long and more than likely, you will find (or think you have found) a pattern. Humans are exceptional at doing this, and it has been theorized this helps with the whole Fight or Flight instinct (Is that the bushes or is there really a tiger there?).The lesson here is that as long as the user thinks it is “random” it can be called random.

Thus, properly aligned on this concept, I go off on my merry and random way and cooked up a solution.

Now, before I go into pure SFDC formula awesomeness mode, I want to call out that this is probably my 50th iteration (maybe slight exaggeration) of this functionality. BUT, I want to also call out that Salesforce is probably the best platform I know of for this type of work. Quite literally, I would have the tab view up on the screen and in a new chrome tab the formula field for constant tweek / refresh. So, back to the awesomeness.

I decided that I will need two things to get my random number:

1)      A pool of numbers

2)      A “dice” function

To generate the pool of numbers, I decided to use the NOW() function along with the square root function. The NOW() function gives me an ever changing value and the square root function gives me a way to expand on that changing value. At first, I tried using just the minute function to get my pool, but ran into issues because the numbers were quite large enough. That is not to say it wouldn’t have worked, but it just didn’t make me happy. Then, around PI day (3/14) I had an inspiration! I remembered that there were certain sequential dates that only occur once in a millennia like “11/12/13”. I already had a really REALLY good seed, the date itself. This is because NOW() returns Month/ Day/ Year Hour / Minutes / AM PM. That might be a bunch of text, but if you break it down a bit more, you will see where I am headed:

NOW() = 3/19/2014 9:25 AM = 3192014925 = 31920141625

That last value might look a little funny and that is because it is. I noticed that when I ran a formula to derive hour from now <(left(right(text(now()),9),2)))> the return result was actually not matching with what I saw. Turns out, the hour value was being formatted into 24 hour UTC.

Deep Breath! With all this said, what I have is this great formula that returns a number that WILL NEVER HAPPEN AGAIN (Kerplew, Mind Blown and it is only Thursday) and can now work my random magic on it, and by magic, I mean the square root function.

The reason I use this function is because, well, it generates a gnarly set of digits. According to the Wikipedia page, “In mathematics, a square root of a number a is a number y such that y2 = a, in other words, a number y whose square (the result of multiplying the number by itself, or y × y) is a.[1] For example, 4 and −4 are square roots of 16 because42 = (−4)2 = 16.”, in other words, for every number, this is another number that when multiplied against itself will return the first number.

Thus, I get the following number formula with 9 digits after the decimal:










There are a couple things I need to call out:

1)      I put the “/100” in there because the returned number was so large and the differences (minutes) so minute (ha) that the square root function was not returning really good results. Once I threw that “/100” in there, I started to get much more amazing data.

2)      The order of operation starts with the minute function. This is to keep things more random. Basically, if you started with the Date values, the leading digits would be the same for 24 hours. This way, they are refreshed every minute.

Now that you have a pool of numbers, you would need to generate your “dice” criteria.

The dice is what selects from the pool the actual number. In excel, this is similar to the “RANDBETWEEN” function. I put together a quick dice criteria in excel so that I could demonstrate the randomness. It uses a combination of the length of the user’s first name & the numerical position of the first letter of the first name. What this means is that ANDREW = 6 digits and A = 1, so my “dice” number is 6-1. IF my first name was BART, then the “dice” formula would be 3 (BART = 5 digits and B = 2). I used this “dice” formula on my pool results, and for it being a thrown together criteria, I did see some very nice and random results. Unfortunately, chatter posts are not very nice with formatting that data, so you would need to look at the attached docs!

And thus, with this knowledge, you will be on your way to generating your own take on this, which is what will truly make your number random! Now, was this all just for fun? Nope! One possible application for this could be for the assignment of incoming records like leads or cases where you might not want a round robin or first in / first out rule setup.


Thanks for playing along! If you like this, be sure and share. If you have questions, well, let me know!

Russell Wilson, Football, Baseball and Salesforce


The Seahwaks second year quarterback is Russell Wilson. Russell has a great story that builds up to my point, so bear with me. Russell walked on at Wisconsin and ended up leading the team to the Rose Bowl, not to out the ordinary except that Russell wasn’t even the starter when he got to Wisconsin. Russell was then drafted in the 5th round by the Seahawks, shocking a lot of people because he wasn’t built like your typical quarter back (5’ 10” instead of a typical 6’ 4”). His rookie year he won the starter job from Matt Flynn, which surprised just about everyone but his mom, and even then, his mom was only surprised at how quickly it happened. This year, the Hawks are 11-2 and have clinched a playoff spot. Despite all this success, the Ranger’s just announced that they drafted Russell in the 5th round of their rule 5 draft. Just to be clear, the Rangers are a Major League Baseball Club.

So, the question is “why”. Why would a baseball club spend a draft choice on a very successful football player. The answer provided by the Sports Illustrated section “Audibles” provides a very clear explanation:

“Because Wilson was taken in the AAA-level section of the draft, the Rangers can stash him on their roster, in case he ever stuns the football world by bailing for the diamond.”

It is all about stashing talent, kind of like a rainy day fund for sports.

Like the Rangers, are you stashing any thing away for a rainy day (Ideas, not Athletes!). Is it that crazy idea you have around workflows, perhaps it is documentation or that great thread you found about visual force? Perhaps it is a tweet? I don’t know what is in yours, but I know that I have a very full clever ideas / awesome insights / cool tips rainy day fund that I am looking forward to sharing. 

When working with Cloud Apps, in my case it is, tinkering almost seems to be encouraged. There is a very open community of folks who share ideas and are consistently driven to find new and better ways of doing things through new tools and features.

My Intellectual Property rainy day fun spans quite an area, from business to marketing and back to Salesforce, but I feel that having a well-diversified portfolio helps when it comes to real life an intellectual capital.

–      Andrew