I know this title would have been better for Halloween. Just think of the scary title not in honor of Halloween, but has a foreshadow of the scary times to come – Holidays with the extended family.
Now that we’ve gotten our shivers out of the way, let’s talk about Headless Flow.
What is in a name
Let’s start with some definitions here.
- Visual Workflow: This is the name of the product. Think Analytics Cloud – which is the name of a Salesforce product.
- Flow: This is what we build with Visual Workflow. If Analytics Cloud is our product, reports & dashboards are what we build with the product.
- Headless Flows and Trigger Ready Flows: These two terms mean the exact same thing. The basic definition is headless Flows contain no screen elements. There’s nothing visible presented to the user.
- Flow Triggers: For people in the Flow Trigger pilot, this was a Workflow Action that specified a Flow and variables for that flow. A Flow Trigger is a Workflow Action just like Field Updates and Email Alerts.
- Launch A Flow: The new Lightning Process Builder has an action named “Launch a Flow.” This is basically a Flow Trigger, but for a Process and not a Workflow Rule. Going forward, this is how you will be able to call Flows from a workflow type action. The Flow Triggers for Workflow Rules will not be going Generally Available per the Product Manager at Dreamforce. Instead, we will be launching Flows using the Process Builder.
Hopefully this helps clear some confusion. The two key points to take away here is that a Headless Flow is the same thing as a Trigger Ready Flow. The second key point is the only requirement is the Flow cannot have any screen elements. A screen element is what you use in Flow to present something to your user. It could be simply displaying text or it could contain fields for the user to fill in.
What Can I Do With a Headless Flow?
What can’t we do! You can still have logic in your Flow with decision elements. You can lookup, create, update and delete records. You can send emails, perform Chatter Quick Actions, Submit for Approval, and basically any action or element that is not a screen element.
I’ve used Headless Flows to do complicated calculations that a formula field can’t handle. For example, check to see if every field is filled in and calculate a percentage of completeness of a record. I’ve also used Headless Flows for updating multiple child records and creating specific records based on logic.
Great, I Have a Headless Flow – How Do I Use It?
There are four ways to “call” a Headless Flow:
- Workflow Rules: If you’re in the pilot with Flow Triggers you can call a Headless Flow from a Workflow Rule. At Dreamforce, I heard this will not be going Generally Available and instead will be replaced with…
- Process Builder: Aka Lightning Process Builder. This was announced at Dreamforce. You may have seen it at a session. The Process Builder is in Closed Beta in Winter ’15, but as I mentioned in my post Dreamforce Special: Hands on the New Process Builder you can submit a support case to get access to the closed beta. The Process Builder includes an action called “Launch a Flow” which will “fire” a Headless Flow.
- APEX: Who doesn’t love to write APEX? You can call a Headless Flow with the interview.start() method. Which is great if you have no other choice. You can put your logic and actions in a button click friendly place and use APEX to simply trigger it.
- URL: The above options let you call the flow automatically. You can still use a Headless Flow by using the Flow URL. Combine that with a custom button or a custom link and you’ve got the power of Flow with a click of a button.
So What Do I Use?
Obviously from my past posts, I’m a big fan of the Process Builder. You want to use just what’s generally available? Well then you’re stuck with APEX and URL. There’s a couple of crafty things you can do with the URL:
- Use a Custom Button/Custom Link: Paste in the Flow URL and any variable values you need (more on that later) and you’re set
- Use the retURL parameter to “link” towards a flow. Go edit a record in Salesforce and look at a URL. Go on… I’ll wait… Notice the parameter “retURL” in the URL? This tells your browser what URL to take you to when you complete an action. For example, if you click the save or cancel button. You could use the retURL in a custom button, link or other URL to pass the user to a Headless Flow. You can even chain them to multiple flows which is pretty darn cool.
Technically speaking, a Headless Flow could simply contain a single element. For example, a Flow that as a single Record Create element that creates a task is a perfectly valid Headless Flow. What if you want to reference a record or make a related record? For example, let’s say we’re on an Opportunity and we want to create a bunch of tasks associated to the Opportunity Owner. To do this, the Flow needs to know:
- Opportunity Record ID
- Opportunity Owner’s User ID
So how do we get that information to our Flow? Well, we could pass both pieces of information into the Flow, but we can find the Opportunity Owner if we know the Opportunity Record ID. So we only need to pass the Opportunity Record ID into the Flow.
First, we need to have a variable for the record ID. A variable in Flow simply is a place to store a value. It could be text, number, currency, date, datetime or boolean (true/false). We’re going to create a text variable called “varOptyID”
Right below the Data Type field is a field called “Input/Output Type.” This controls if we can pass a value to this variable from outside of the Flow and if we can get the value of the variable from outside of the Flow. We need to be able to tell the Flow what the value of the record ID so we’re going to set it to “input and output.”
Once we have our variable we can add the elements to lookup the Opportunity with a Record Lookup element and grab the OwnerID. Then we can create our tasks with Record Create.
When you use a Flow Trigger or the Process Builder, you can specify the variables and their values for the Flow. The only requirement is the variable must at least be set to Input.
When using a Flow URL you pass the value of the variable as a URL Parameter. So let’s say our Flow URL is “/flow/OptyTaskCreate” to pass a variable value into this flow we need to put the variable name in the URL. First, we need to let the URL know there’s going to be variables. We do this by putting a ? in the URL, then the variable parameter followed by = and the value. So at the end we have: “/flow/OptyTaskCreate?varOptyID=006E0000003wTWM”
It’s very important to make sure you put the name of the variable exactly as how you have it in your Flow. It is case sensitive so varOptyId would not work.
You can pass multiple variables into your Flow. Just separate each variable=value with a &. Example varOptyID=006E0000003wTWM&OtherVariable=Value
The last thing you may want to include with the URL is a retURL. This will make sure your users go where you want them to go. The only requirement is you can only send them to an existing record. To turn them to the Opportunity they came from, your URl would look like this: “/flow/OptyTaskCreate?varOptyID=006E0000003wTWM&retURL=/006E0000003wTWM”
I hope this helps clarify how to use Headless Flows. I’m working on a video training series on Flow so look for a videos coming soon! What are you using Headless Flow for? Let me know in the comments!
Thank you to everyone who voted and commented on the poll. I greatly appreciate the feedback and will try to incorporate as much of it as I can.