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:


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.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments