Expert Flow Topics – Genetic Flow Patterns & Flow Metaprogramming

Every Flow is completely represented by a single piece of XML metadata, and you can download a Flow xml file, modify it, and redeploy it.

But of course, you don’t. Because it’s dangerous to hand-modify the XML. It’s easy to break things down there in the basement. So we try to provide Flow users with all the tools they’ll ever need right in Flow Builder and/or via public, well-defined APIs.

It is possible, though, to start with a flow (‘templateflow’), modify it using basic text parsing and substitution, and deploy the resulting flow (generated flow’).

Suppose that you resolved to start with an existing Flow XML file, and write some Apex code to modify it. You then deploy the modified version of the file up to an org, as a working generated Flow.

You are now programming Flows in Apex. So far so good.

Now suppose that you take that Apex code and turn it into an invocable action that you can insert into a Flow. You then create a Flow that gathers configuration data from a user using standard Flow screens, passes those inputs into your invocable action, and the invocable action then generates a Flow using the inputs the user provided? You now have a Flow Generator. You’re using Flows to generate other Flows. This is a powerful concept known as metaprogramming.

I did some experimentation this year with this, and have published a page of information about it here. There’s a repo you can look at with a working example of flow metaprogramming, used to generate custom Lead Conversion flows.

Consider another scenario: you want to change Flow Stages resources dynamically. Currently you can’t access them with conventional tools like Assignment elements. However, in a flow metadata file, they are simply represented like this:

<stages>
        <name>Stage1</name>
        <isActive>false</isActive>
        <label>Stage1</label>
        <stageOrder>1</stageOrder>
    </stages>
    <stages>
        <name>StageB</name>
        <isActive>false</isActive>
        <label>StageB</label>
        <stageOrder>2</stageOrder>
    </stages>

You could start with a template flow as your baseline, and then use a Flow Generator to read Custom Metadata values, swap in the values for things like the stages name element, and deploy the resulting customized flow.

Good hunting.

New Wiki Page on Flow Stages

We’ve added a new wiki page covering Flow Stages. As is the case with most buildouts of the wiki, this isn’t about a bunch of new content but more of an aggregation of all of the known existing good content on a single focused topic page. As such, everyone should feel encouraged to add good links to wiki pages like this one. The link at the bottom of the page explains how to do it, and it’s totally safe: all edits are put in a review queue so you don’t have to worry you’ll mess anything up.

From ForcePanda: The first Invocable Action that can perform SOQL on any kind of input

Narender builds on his “world’s first” blog post on invocable actions that use the new Spring ’20 generic SObject support with a new post that shows, for the first time, an action that carries out SOQL and can be used declaratively in any object scenario.

The heart of his action is this line:

string query = 'Select '+ queryParams[0].fieldsToQuery + ' FROM ' + queryParams[0].objectApiName + ' LIMIT ' + queryParams[0].numberOfRecords;

As you can see, that’s a SOQL query. Now you’ve always been able to do that with a Flow invocable action, but you always have had to get into the Apex code and specify the exact object you wanted to use. For example, when I posted this tutorial on injecting advanced soql into flows, you can see that my code specifically declared User and Contact variables.

But Narender’s code doesn’t have to do that. And that means that you can take his action and deploy it declaratively against any kind of input.

ForcePanda’s example, powerful though it is, only scratches at the surface of the powerful SOQL actions that will be packaged up into building blocks once Spring ’20 ships. And eventually, we’ll start seeing those actions with friendly configuration UI’s, powered by Custom Property Editors.

A New Datatable Component that supports ALL Custom Objects from Tigerface Systems

Tigerface has posted a free version on AppExchange of their upcoming Datatable solution. The thing that really jumps out at me is that they’ve addressed the core limitation of the existing unpackaged datatable flow screen components: its inability to support more than a modest set of standard object types.

Tigerface appears to be solving this via metaprogramming: they actually generate the component on-demand to fit a particular specified object type. That’s a clever approach.

Comment thread here: https://success.salesforce.com/0D53A00004inprz

Navigate Everywhere – Flow Action

This builds on recent work Eric Smith did to expand the range of navigation choices available in a single, straightforward navigation action for Flow. Navigate Everywhere should be able to replace all of the previous navigation components. It provides support for navigation from a flow to:

  • a record page (in edit or view mode)
  • a new record form for an object
  • a list view (object home page)
  • a web page
  • a related object list view
  • an App page
  • a custom Tab page
  • a named page (examples include ”home”, “today”, “chatter” and a variety of community named pages)
  • a Knowledge page

Note that this navigation component is still constrained by some basic limitations constraining navigation in Flow Builder. This will work in normal lightning experience flows, including flows launched from Quick Actions, but will not work when run from inside Flow Builder or via a Custom Button. It will not work from Visualforce pages.

Supported Destination Types

Destination Type = ‘Object’

Will navigate to a New record form or a List view. Note the use of DestinationActionFilter to pass in the name of a specific list view.

Destination Type = ‘Record’

Navigates to a specific recordId in either view or edit mode. Don’t use this Destination Type if you’re trying to create a new record (Use Destination Type = ‘Object’). DestinationAction is basically ignored for this DestinationType, and DestinationActionFilter is not used.

Destination Type = ‘App’

Navigates to an app. For DestinationName, use either the appId or appDeveloperName to the appTarget. The appId is the DurableId field on the AppDefinition sObject. The appDeveloperName value is formed by concatenating the app’s namespace with the developer name. To find the app’s developer name, navigate to the App Manager in Setup and look in the Developer Name column. For standard apps, the namespace is ‘standard__’. For custom apps it’s ‘c__’. For managed packages, it’s the namespace registered for the package.

DestinationAction and DestinationActionFilter are not used.

Destination Type = ‘URL’

Navigates to a specific url. Use the DestinationURL field.

DestinationName, DestinationAction, and DestinationActionFilter are not used.

Destination Type = ‘NamedPage’

Navigates to a specific Named Page. Use the DestinationName field.

In Lightning Experience and the Salesforce mobile app, possible values are:

  • home
  • chatter
  • today
  • dataAssessment
  • filePreview

In Communities, the value for pageName is the URL value for a supported page. For instance, the default URL value for the Account Management page is /account-management, so the value for pageName would be account-management. The value of home is reserved for the landing page of any community in your org.

Supported pages in Communities are:

  • Home
  • Account management
  • Contact support
  • Error
  • Login
  • Top Articles
  • Topic Catalog
  • Custom pages

DestinationAction, and DestinationActionFilter are not used.

Destination Type = ‘tab’

Navigates to a specific tab. Use the DestinationName field and provide the unique name of a CustomTab. Visualforce tabs, web tabs, Lightning Pages, and Lightning Component tabs are supported.

DestinationAction, and DestinationActionFilter are not used.

Destination Type = ‘knowledge’

Navigates to a knowledge page. Destination URL is required. The value of the urlName field on the target KnowledgeArticleVersion record. The urlName is the article’s URL. DestinationName is ignored for Communities but required otherwise. Use the ArticleType API name of the Knowledge Article record for DestinationName.

DestinationAction, and DestinationActionFilter are not used.

Destination Type = ‘relatedlist’

Navigates to a related items page. Requires 1) a RecordId 2) a DestinationName like Case, 3) a RelationshipName like CaseComments and 4) a DestinationAction (which here has to be view)

Attributes

AttributeTypeNotes
DestinationTypeStringAllowable values include ‘object’
DestinationNameStringWhen DestinationType is ‘object’, this must be an object name like ‘Account’ or ‘MyObj__c’.
DestinationActionStringWhen DestinationType is ‘object’, supported values are ‘list’, ‘new’, and ‘home’
DestinationActionFilterStringWhen DestinationType is ‘object’ and DestinationAction is ‘list’ or ‘home’, this allows the specification of a specific list view by name. Example ‘mycustomlistview’
Destination URLString
Relationship NameStringUsed with Destination Type = relatedlist
Destination Record IdString

Install

Unmanaged Package 1.0

View Source

Source

Get a Layout’s Field Names – Flow Action

With the publication of the RecordDetail flow screen component, it became easy to get flow to show any list of field names you choose to give it. In many use cases, you might want to leverage your existing Layouts, particularly in situations where you’ve customized layouts on a per-record-type basis. Other recent tools make it easy to let users select record types and obtain layout id’s. This action takes a Layout Name and Object Name and returns a CSV string of the layout’s field names. To see this action in action, check out this video.

Inputs

AttributeTypeDescription
Layout NameStringexample “Account (Marketing) Layout”
Object NameStringexample “Account”

Outputs

AttributeTypeDescription
layoutFieldsCSVStringComma-separated list of layout fields

Installation

Install this action as part of the QuickChoice managed package or just grab the source.

Get the Layout Corresponding To a Specific RecordType/Profile Combination – Flow Action

Layouts often differ substantially from recordType to recordType and from profile to profile. This action takes a recordTypeId and a profileId and returns that combination’s current LayoutId. One use of this is dynamically generating flow screen layouts with the RecordDetail flow screen component. To do this, after using this action to retrieve a LayoutId, use the GetLayoutFields action to retrieve the list fo field names from that layout. You can then pass the list of field names to RecordDetail to generate a customized record detail right in your Flow screen that maps to the layout. To see this in action, check out this video.

Inputs

AttributeTypeDescription
recordTypeIdStringThe ID of a recordType
profileIdStringThe ID of a profile. Note that you can quickly generate this in Flow by creating a formula of $User.profileId

Outputs

AttributeTypeDescription
layoutIdString

Installation

Install this action as part of the QuickChoice managed package or just grab the source.

Quick Choice – Improved Picklists and Radio Buttons for Flow

Quick Choice is a flow screen component that provides some features that aren’t available in the current picklist and radio button implementation in Flow Builder.

Features that SmartChoice provides:

  1. Accepts as an input a pair of string collections.
  2. Can accept a default value that’s dynamically determined by your Flow
  3. Can generate picklists from existing picklist fields with optional filtering based on recordType
  4. Supports ‘None’ Value and Requiredness
  5. Choices can be formatted as Radio Buttons, Picklist, or Visual Cards
  6. Visual Cards can be displayed with or without Icons
  7. Visual Cards can be displayed in single or dual columns

SmartChoice supports both picklists and radio button groups, set by passing in an Display Mode. For this document, we’ll always use “Picklist”. There’s no support for multiple select. If you need that, consider the Dual List Box flow screen component.

Creating Choices from String Collections

Use String Collections as your inputs by setting Input Mode to “Dual String Collections”. Pass in one collection for Labels and one for the underlying values (A typical use case for this is when you want your user to see a list of friendly labels, but you need to make sure that you can get the recordId of the selected label.)

Example: You want your flow to let the user choose a record type from a picklist and then display the layout corresponding to that record type (This is demonstrated in the video above). The Quick Choice package includes several utility actions that make this easy. You first start out with the GetRecordTypeInfobyObject action, which returns separate collections of recordTypeNames and Ids. You then use those as inputs to a QuickChoice control. When the user makes their choice, you use a couple of additional utility actions to extract the Layout fields for the layout that corresponds to the combination of the selected RecordType and the running user’s profile. The layout fields are then passed to the new RecordDetail flow screen component.

Tip: If you are starting with a collection of SObjects instead of a collection of Strings, you can use the ExtractFieldFromCollection flow action (provided in the same package as SmartChoice) but you’ll need to modify its Apex, swapping the references to “Account” for your chosen SObject.

Creating Filtered Choices from Picklist Fields

Many orgs take advantage of the ability to create record-type-specific sets of picklist values for picklist fields like Account.Type and Account.Rating. Flow already enables the easy creation of Picklist Choice Sets, which point at an existing picklist field. But you can’t filter a Picklist Choice Set on a specific Record Type. Quick Choice allows you to do that.

Start by setting the Input Mode to “Picklist Field”.

Pass in a string to ObjectAndFieldName that uses dot notation, like this: “Account.Type”. (If you’re using the Object and Field picker, use a formula resource to join the two values into this format)

Pass a record type ID in. If you don’t, the component uses the ID of the standard “Master” record type ID, which will result in no filtering. This package includes a useful utility function called GetRecordTypeInfoByObject that will return the record type Id’s and Labels for a given object type name. The video above shows how you can use QuickChoice first to let the user select a record type and then to show a set of filtered picklist fields.

Displaying Choices as Visual Cards

Set the Display Mode to “Card” and the Input Mode to “Visual Text Box” .

Pass in a collection of Strings in Choice Labels for the visual card headers, a collection of Strings in Choice Values for visual card descriptions and optionally a collection of icon references in Card Mode – Choice Icons for visual card icons.

If you are displaying icons, set the Card Mode – Include Icons in Display Box? parameter to True and set the Card Mode – Icon Size parameter.

The visual cards are displayed in a single column by default. Set the Card Mode – Number of Display Box Columns (1 or 2) parameter to 2 to display dual columns.

Visual Cards without Icons

Visual Cards with Icons

Dual Column Visual Cards

Requiredness Support

You can set the Required field to $GlobalConstant.True. If you do, Flow will prevent screen transition if the user selects ‘None’ or makes no selection at all.

Controlling the ‘None’ Choice

By default, there will be no “None” Choice. To add one, set the input “Allow None To Be Chosen” to $GlobalConstant.True.

Reference

General Attributes

AttributeTypeNotes
Master LabelStringThe main label for the picklist or radio button group
Display ModeEnumEither “Visual”, “Picklist” or “Radio”, depending on which control you want
Input ModeEnum“Single String Collection”, “Dual String Collections”, “Picklist Field”, or ” Visual Text Box ” are currently supported
RequiredBooleanWill prevent transition if set to {!$GlobalConstant.True}
ValueStringThe selected value. This can be passed into QuickChoice, allowing you to set the default value dynamically.
Allow None To Be ChosenBooleanSet this to true to include a None choice. (For Input Mode “Picklist Field” only)

Additional Attributes When Using Input Mode = “Single String Collection”

AttributeTypeNotes
Choice ValuesString CollectionThe values of your choices (The same collection will be used for Labels and Values)
The selected Label/Value will be returned by the component

Additional Attributes When Using Input Mode = “Dual String Collections”

AttributeTypeNotes
Choice LabelsString CollectionThe labels of your choices
Choice ValuesString CollectionThe values of your choices (should be unique)
The selected Value will be returned by the component

Additional Attributes When Using Input Mode = “Visual Text Box ”

AttributeTypeNotes
Choice LabelsString CollectionThe labels of your choices (should be unique)
The selected Label will be returned by the component
Choice ValuesString CollectionThe values of your choices (This is provided as extra descriptive text in the visual card)
Card Mode – Choice Icons
(OPTIONAL)
String CollectionIcon names formatted as icon_type:icon_name (Example “utility:attach”)
See complete selection at https://lightningdesignsystem.com/icons/
Card Mode – Include Icons in Text Box?BooleanDisplay the provided icons in the visual card
Card Mode – Icon SizeStringOptions include xx-small, x-small, small, medium, or large. This value defaults to medium.
Card Mode – Number of Textbox Columns (1 or 2) String1 or blank (default) for a single column or 2 for dual columns

Additional Attributes When Using Input Mode = “Picklist Field”

AttributeTypeNotes
Object Name (for Picklist Field)StringExample: “Account” (this component no longer uses the combined “Account.Type” as an input)
Field Name (for Picklist Field)StringExample: “Type” (this component no longer uses the combined “Account.Type” as an input)
Record Type IdStringThis will default to the id of the Master record type

Install Package

Managed V1.23 (Production/Developer)
Managed V1.23 (Sandbox)

Version History

1/16/20Eric Smith
v1.23 – Added an option to display the visual cards in a single or dual columns

1/3/20 -alexed
v1.20 – changed actions to global from public to make them visible in flow builder.

12/31/19Eric Smith Enhancements
v1.17: Added visual text box selection with or without icons. Fixed error handling when Required is set to True

12/29/19
v1.13: Fixed bug with defaults on picklist control. Added flag to allow or disallow a ‘None’ choice

View Source

Source

Create a Flow Menu for System Admin Tools

System Admin Tools Menu

Over time I have created a number of specialized Flows in my org for System Admins to help fix records or unwind certain processes.  I find these are a much safer way of keeping the data clean rather than trying to remember all the manual steps necessary to update records correctly.

To make it easier to select and run these specialized Flows I wanted to come up with a way to provide a menu of these tools to select from.  On unofficialsf.com, I found a simple Flow Screen Lightning Web Component that could display a list of Flows in the org and return the API Name of the selected Flow.

The first thing I did with this component (flowPickerFSC) was to enhance it by adding some additional attributes to make it more powerful and user friendly.  I added labels and help text for the configuration attributes, created a filter for the flow search, sorted the displayed list, updated the documentation and created install packages for Production and Sandboxes.

One way to use this component to run a flow is to add the OpenURL Flow Action component to the calling flow and pass the URL of the selected flow to it.  I show how this can be done on the documentation page for flowPickerFSC.


For my Admin Tools Menu I wanted to run my flows in place in a pop-up modal window.  Salesforce Labs has a nice app for this on the App Exchange called Launch Flow in Modal.

With just a few minor tweaks to this component, I was able to embed the Flow Picker LWC and use that to select and set the flow to be loaded in the pop-up modal window.

With these changes, my new component is ready to add to any Lightning Home, App or Record page.

  1. – Any random text is OK here as the Flow Name will be reset by the LWC
  2. – This is the standard Salesforce color for Brand (Dark Cerulean)

Here is the component in action:

Here’s hoping this inspires you to try something like this in your own org.


Follow these links for Installation and Source Code:

Source Code

flowPickerFSC

launchFlowModal

Install Packages

Lightning Web Component Bundles: flowPickerFSC

Aura Component Bundles:  ccp_launchFlowModal, ccp_renderFlow

Apex Classes: FlowListController, FlowListControllerTest

Production

Sandbox



Eric Smith – December 2019

How to create a Map collection in Flows by Narender Singh

Narender Singh form ForcePanda wrote a two blog series about using map collections in flows. The second blog makes good use of the new generic sObject support in flows coming in the Spring ’20 release

Part 1: https://forcepanda.wordpress.com/2019/12/17/how-to-create-a-map-collection-in-flows-part-1/

Part 2: https://forcepanda.wordpress.com/2019/12/18/how-to-create-a-map-collection-in-flows-part-2flow-map-methods-spring20delight/