In Automation, Blog, Flow, Tips & Tricks

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:

  1. 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
  2. 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.

 Regular Requirements

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”

Wrap Up

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.

 

Recommended Posts
Showing 13 comments
  • Pat Vachon
    Reply

    Yup. Love using these. Makes for some pretty slick functionality without having to use code.

    I’d like the ability to dynamically send email using a folder of email templates every two weeks based on whether or not it’s been sent to them before and the priority of the email template.

    Can’t dynamically choose an email template and send a contact id through in order to perform the merge.

    Likely can with APEX, but I’d rather not go there.

    So I’ve put together another flow that does the same thing just not dynamically. Each template is specifically placed into the flow. Currently 25 flow elements (5 base elements & 2 for each of the currently 10 templates) instead of the 9 nine I could of had if only the SendEmail template could merge data and accept the body field from an email template.

  • SutoCom
    Reply

    Reblogged this on SutoCom Solutions.

  • Meredith Fay
    Reply

    Thanks so much for this! The definitions really helped clarify what otherwise seemed like interchangeable terms.

  • Wannabee-Wizard
    Reply

    Thank you Mister Wizard! Really helpful.
    I learned how to send an email alert based on a autolaunch flow.
    At first I forgot the “input and output” property for the record Id which was causing an error… Don’t forget this one!

  • Kerri O'Connor
    Reply

    I am attempting to write a process builder that calls a flow. I have a master record (CT) with a related list (CTID). The source of the related list records is an object (CTI). When a new CT is created, process builder will call a flow that will create one new CTID record for each record in the CTI object. I think I have to pass the CT record ID as well as the CTI object id to the flow. But I am really new to this.

    • Brian Kwong
      Reply

      Kerri,

      When you call a Flow from Process Builder, the flow doesn’t magically know anything about the process that is calling it. So you’re correct. If you need to update/reference the record that has triggered the process, you’ll need to pass that information into the Flow via the Flow action.

      Make sure that your variables are at least marked as “Input.” I’ve gotten in the habit of setting any variable I’ll be setting as “Input and Output” due to some legacy bugs.

      Let’s say you want the CT Record to be updated by the Flow. You’ll need to pass the CT Record ID into the Flow with a variable. From your Flow you can do a Record Update using that ID in the variable to find the record. Same goes if you’re looking up related records.

      I don’t have an example in Flow where I’m passing the ID from outside of the Flow. But if you look at my Wizard Apprentice video: https://youtu.be/U8kSMxoiWyk you’ll see how I’m using a variable ID to do a record lookup and fast lookups.

  • Sujeet Poojari
    Reply

    I started my career in Salesforce few months back .I have read many Documentations and websites ,but i found your blog really interesting.Really well written to make the novice grab things practically and quickly .Thankyou Brian .Plz Keep blogging on new things .Your fans are waiting 🙂

    • Brian Kwong
      Reply

      Thanks Sujeet, hopefully my personal life calms down a little bit more and I’ll actually have time to write new blogs!

pingbacks / trackbacks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.