Retrieve and Deploy Metadata with Flow using Transfer Metadata as a Screen Component

The Transfer Metadata component will retrieve or deploy a single piece of metadata to the org that the Flow is running on. It’s designed as a Flow Screen Component.

Provide it the name of the metadata type (“Flow”) and the name of item (“MyFlowApiName”) and it will return the metadata as a zip file. From there, you can do a couple of different things:

  1. pass the zipfile string to Extract Metadata From Zipfile, a Flow Action that returns the metadata as a readable xml string
  2. download the zipfile using the File Download Flow Action

You can deploy metadata by simply passing the xml string and the type and name of the metadata.

This component uses standard metadata apis. They’re asynchronous, so the component will poll once per second to get the status of the transfer. Make sure you don’t transition away from the flow screen while it’s checking. Standard Metadata save-time validation is carried out, so if you try to deploy a invalid piece of metadata, you’ll get back an error message.

This component pairs well with the Flow Picker screen component that lets the user pick a Flow from a picklist. If there’s interest, it won’t be hard to this component to be made more generic so that other kinds of metadata can be selected from lists.

Because this component uses Metadata apis, you’ll need to have a Remote Site Setting on the org. If you don’t, you’ll see an error like this:

To address this, copy the root url from the error message and go to Setup –> Remote Site Settings. Create a new setting.

This configures your org to essentially allow applications to run that call out to the internet and then back into the same org via its api endpoints.

In this application, we want to get the XML displayed on a Flow screen where we can select it and copy it to the clipboard. To do that, we’re going to use this Flow:

After the retrieval is done, the result is an encoded zipfile string that looks like this:

This represents a zipped package that can theoretically contain more than one piece of metadata. In our case, we know that we have a single piece of metadata, so we want to convert this to make it readable. To do that we first pass this encoded zip string to an ExtractMetadataFromZipfile action, which provides a readable string. Then, because we want to show it in a flow screen, we filter it through an Escape XML String action.

Ultimately you have a nice string version of the metadata suitable for further handling:

Big attribution credit to Andy Fawcett. This component stands upon the shoulders of the giant MetadataService, which solved all the hard parts years ago.

Deployment

To deploy metadata, set the transferMode attribute to ‘deploy’ and pass in a viable piece of XML.

Install

This component is part of the Flow Base Packs package libraries.

FBC Version 1.2.2 – Eric Smith – 7/26/20
The Flow will now navigate to the next node upon a successful deploy or retrieve.
Added help text to all attributes

Old Versions

Version 1.0.1 Unmanaged (removed unnecessary files that might conflict)
Version 1.0 Unmanaged

Source

View source