npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flowex

v1.0.2

Published

Apex code generation based on Flow metadata

Downloads

56

Readme

FlowEx

A plugin for sf to convert Salesforce Flows into Apex code

Install and Run FlowEx for end users

Here's the short way to make use of FlowEx to translate ServicesFlow to Apex:

sf plugins install flowex
sf flowex --input-file .\data\ServicesFlow.flow-meta.xml

Install and Run FlowEx for developers

Alternatively, if you have npm and want to play with the source, clone the repository:

git clone https://github.com/steinwinde/flowex.git
cd .\flowex\
npm install

Ignore the warnings. At this point a Flow definition file (*.flow-meta.xml) can be parsed and the resulting Apex sent to standard output. The following uses a Flow definition, which is part of the repository for testing purposes:

.\bin\dev.cmd flowex --input-file .\data\All-GetRecords-Element.flow-meta.xml

Now get the local code working as a plugin of sf:

npm run build
sf plugins link .

FlowEx is a sf plugin now:

sf flowex --input-file .\data\All-GetRecords-Element.flow-meta.xml

FlowEx development

Any relevant code change should come with TypeScript test modules. The project utilizes mocha. Much of the logic is not based on explicit Salesforce documentation, but on knowledge gained by inspecting Flow definitions downloaded from orgs.

What happens during execution

FlowEx is based on oclif. The entry point can be found here.

From there, the tool proceeds roughly according to the following steps:

  • It parses the Flow definition. This is somewhat based on a recent version of Salesforce's Metadata WSDL (download from your Salesforce org via Setup - Integrations - API). It utilizes xml2js to generate a memory representation of the Flow.

  • It then extracts relevant information by looking at Flow elements one-by-one, in several cycles. As everything else in this project, the design here doesn't aim at efficiency and briefness, but at testability and readability.

  • A first internal representation of the Apex is generated.

  • If variables are not all global (like in a Flow execution context in Salesforce, see "globalVariables"), the future place of variables, parameters and return values is calculated.

  • The literal Apex strings are compiled and send to the output.

Limitations

The current version of the code is mostly based on work from summer 2022 and the then metadata format and Flow capabilities. The code has never attempted to cover formulas. It has never covered all available Flow elements and options. The produced Apex has significant design deficiencies, e.g. it is not bulkified.

The produced Apex should never be used as such.

Why convert a Flow to Apex?

When Apex and Flow look like possible options to implement a requirement, Salesforce recommends Flows. Companies agree: The number of those who feel (and in many cases are) capable of developing and maintaining Flows is much larger than those that can write Apex, and they tend to be less expensive.

One consequence of the partiality of the main actors is the presence of logic implemented in Flows that better was implemented in Apex - not necessarily when it was set up initially, but definitely in its evolved shape, when we come across it.

This tool doesn't take a position in the battle of Flows and Apex. There are excellent articles discussing the subject (see here and here). Data volume, speed, complex logic and queries are commonly named as drivers to choose Apex. At some point, extending an existing Flow becomes untenable. At this point an automatic conversion comes in handy.

And there are much less considered reasons to convert a Flow to Apex: not in order to execute Apex, but for inspection. Think of

  • how you track changes between Flow versions in source control;

  • the amount of required screenshots necessary to state a question regarding Flows on StackExchange or Trailblazer Community groups;

  • what it takes to understand changes between an active and a more recent version of a Flow, when work stalled a while ago and you completely forgot its history;

  • or what it takes to understand similiarities of two Flows developed in different contexts.

In all these situations comparing Apex is much better suited than comparing Flows in Flow builder or comparing the XML of Flow definitions.