Tutorial: Schedule a Flow to Delete Old Files (ContentDocuments) – Featuring New ‘AddQuotesToFields’ Action, ExecuteSOQL, and ExtractStringsFromCollection v2

Check out the video walk-through here.

With all of the new actions coming I thought I’d share a ‘bring it all together’ tutorial that outlines several actions here on USF:

I strongly recommend you reading up on Salesforce Files before tackling this, it will make the SOQL queries a lot easier to grasp.

One of the limitations (as many of you are aware) of the standard ‘Get’ elements of Flow is you that you cannot reference related fields like you can in SOQL. This usually isn’t a huge problem for standard and custom objects since you could in theory just create a formula field as a workaround. But what about objects you can’t create formula fields for like ContentDocumentLink?

Enter ExecuteSOQL. With this action you’ll be able to do the same things those fancy Apex guys and gals can do to manipulate and work with Files.

One “fun” limitation of querying ContentDocument is that you can’t use handy relationship queries for what you need – you have to get to them indirectly through ContentDocumentLink. The below example will not work:

SELECT Id
FROM ContentDocument
WHERE Id in (Select ContentDocumentID from ContentDocumentLink where LinkedEntityId in (blah blah blah)

What you’ll see developers frequently do is construct a List of ContentDocumentLinks and grab the ContentDocumentIds tied to each of them. Then they re-query ContentDocument to get their ContentDocument list which they can then update/delete/do whatever with. That’s what we’ll be doing in our second Flow!

View All Files Permission

Spring ’19 enabled the ‘View All Files’ permission which finally allows us to directly query all files in ContentDocument and ContentVersion. This is extremely handy – if you simply want to archive or delete ANY old file, you can now do that using simple SOQL queries or even a Get in Flow. You will need this enabled in Scenario 1.

Scenario 1 – Delete Old Files Posted by Community Users

Suppose you wanted to schedule a cleanup flow to delete old files posted by Community users – check out how you’d do this below!

NOTE: Always have fault paths on your actions! I skipped that for example-sake.

Step 1 – Use the ExecuteSOQL action with the below query to grab all Files that are > 2 years old and created by the Community User profile
Step 1 Continued – See above for the SOQL statement
Step 2 – For older versions of ExecuteSOQL you will need to assign the results to a number. The latest version of ExecuteSOQL posted this week does not need this step.
Step 3 – Do a decision on the number field you just assigned.
Step 4 – Delete the returned ContentDocuments from the ExecuteSOQL action

Scenario 2 – Delete Old Files Posted in Certain Accounts

A bit more advanced here – let’s say you wanted to clean up some files on a subset of records. In this case it would be a set of Accounts based on a Type field, but it could be any object. Check out the steps below on how you’d accomplish that.

NOTE: Always have fault paths on your actions! I skipped that for example-sake.

Step 1 – Set up your ExecuteSOQL action storing it in a ContentDocumentLink record collection variable. See below for the query
Step 2 – Create your SOQL statement. Fill in whatever Day value you want for grabbing old files.
Step 3 – For older versions of ExecuteSOQL you will need to assign the query results to a number to do your null check.
Step 4 – Do your null check decision on the number value we just set in the previous step.
Step 5 – Run the latest and greatest version of ‘ExtractStringsFromCollection‘ action to get a comma-separated text variable of all of the ContentDocumentIds
Step 6 – Run the new ‘AddQuotesToFields’ action to wrap each ID in quotes so that we can easily throw it into the next ExecuteSOQL action.

NOTE: If you don’t want to install this action you could still create a Loop to create your own ContentDocument collection.
Step 7 – Run the last ExecuteSOQL action using the query below to generate your ContentDocument collection you will be deleting.
Step 7 Continued – Here’s the query you will run. Notice how we throw in the output of the ‘AddQuotesToFields’ action into the query itself.
Step 8 – Delete your files!

Develop Custom Property Editors Quickly with Flow Combobox

Updated: 1/11/25 – Eric Smith – (FlowScreenComponentsBasePack v3.3.8 or later)

  • Flow Combobox now supports Action Buttons and Screen Actions in Custom Property Editors
  • CPE developers can allow manual entry of attributes in Flow Combobox to support outputs from standard components like Transform and Filter

Flow Combobox is a combobox that’s intended for use by developers who are building custom property editors. It’s not something you’d drop onto a flow screen.

What it does is provide a ready-to-use combobox that’s smart enough to extract from the information provided by Flow Builder all of the available mergefields. You can use this as a CPE developer to enable admins configuring your extension to apply references that will be dynamically resolved when the flow is run.

In doing this, Flow Combobox is simply emulating, as best as possible, the functionality provided in Flow’s native property editors .

Here’s the native Flow version:

and here’s the Flow Combobox:

Using Flow Combobox
The flow designer can enter a literal value, or choose a mergefield from the list. Literals are always reported back to Flow Builder in dispatched events as having type = String. values chosen from the list will always be reported back to Flow Builder as references (mergefields).
All reference variables are surrounded by {!variableName} in edit mode, if user removes {! }, value will be converted in a literal automatically. If user types in a value that is surrounded by {! }, component will perform an attempt to find this variable in builderContext, and in case of failure will render an error and return false via reportValidity .
If selected parameter is valid builderContext variable it will be rendered as a pill with no errors.

Attributes

name (required) – unique String, that represents name of the component, used as a key in “valuechange” events.

label (required) – String used to display a label above the combobox

builderContext (required) – this attribute gets populated with information about the underlying Flow, including its input attributes, current values previously provided by the user, and more.

The value and valueType attributes represent the selected current value. Inspect the underlying input attribute in the passed in builderContext when initializing to determine whether there’s an existing value that needs to be loaded into the combobox.

  • valueย (optional) – String, determines the value the component will be initialized with. Must be a valid value from builderContext. This value can be a reference to an SObject or a literal value. Whenever this is set to an SObject reference, flowCombobox will enable traversal of the object’s fields
  • valueTypeย (optional) – String(valid values are ‘reference’ or ‘String’). This instructs Flow Builder whether to treat the value as a literal string or a reference to an SObject. Default is “String”

builderContextFilterType (optional) – String. Use this to filter the contents of the combobox to show only a specified type of object. Note that this is different from the type in valueType.

builderContextFilterCollectionBoolean (optional) – Boolean, if true, flowCombobox will show only collection variables from the builderContext

New Attributes by Eric Smith
disabled (optional) – Boolean, set this attribute to true when you want to show the combobox as disabled in the CPE

allow-hard-code-reference (optional) – Boolean, set this attribute to true when you want to allow the user to manualy enter an attribute. This is useful for specifying resources that aren’t currently supported by the combobox such as outputs from Transform or Filter elements. Entry format is {!attributeName}

placeholder-text (optional) – Show placeholder text in the combobox input. Example: "Manual Entry Allowed"

New Attributes by egolden-tc
autocomplete (optional) – this maps to the standard autocomplete field on lightning-input. By default it is set to “off”. This ensures browser autocomplete dropdown doesn’t cover or conflict with the combobox options. It can be changed to “on” to revert to the original behavior.

field-level-help (optional) – this maps to the standard field-level-help on the lightning-input. If a value is provided it will show as help text on the combobox to give users context on what they are selecting and/or why.

automaticOutputVariables (optional) – this can be used to pass through the automaticOutputVariables data structure that Flow Builder makes available to Custom Property Editors, similar to how you pass builderContext through to this component. Learn more here.

Methods

reportValidity – returns false in case if component has any validation errors

Search behavior

Typing into the combobox input field will search on the apiNames of available mergefields. This search will respect filters put in place by the search string,flowContextFilterType, and flowContextFilterCollectionBoolean. If the type is “String”, however, it will also shows SObject records with a traversable “>” to allow users to traverse to fields of the SObject.

Default Behavior

The only default behavior change is the disabling of the autocomplete. This is probably desirable but the behavior can be reverted to the previous default per the above options.

Install

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

View Source

https://github.com/alexed1/LightningFlowComponents/tree/master/flow_screen_components/FlowScreenComponentsBasePack/force-app/main/default/lwc/fsc_flowCombobox

From Ragan Walker and CapTech: Easy Deduping with the new ‘Extract Strings from Collection’ Action

CapTech has been on fire lately with their contributions to the community, most notably with their extremely feature rich CSV Exporter. In the latest Collection Actions v1.17, they’ve upgraded Extract Strings from Collections by adding an optional Dedupe capability, as well as the following enhancements:

  • Supports extracting + deduping of multi-select picklist fields
  • Returns a CSV string of fields in addition to the collection for easier processing in Flow

as well as:

  • Supports bulkification
  • Adds exception handling to make action more robust
  • Adds further unit testing

Install the latest Collection Actions set here.

Summer ’20 Preview: New Lookup 3.0 with Custom Property Editors and ‘Add New Record’

If you have a Summer ’20 org (Preview Releases available now, Sandbox Preview on 5/30), you can try out this cool new Lookup component. On the Flow screen, it provides searching, pills support, and an optional ‘Add New Record’ capability:

When the user clicks Add New Record, a modal record form is shown (using the latest version of RecordDetail, which can also be used standalone in flow screens), and the layout fields corresponding to the running user’s profile are shown. In the property editor, it looks like this:

Developer Notes

“Display which Field” and “Output which Field” use the latest version of the PickObjectAndField component. As before, this version provides the ability to drop an Object and Field picklist pair into your custom property editor. The latest version adds the ability to provide a list of all available Flow merge fields. This allows the flow designer to set the object dynamically

Comparing the Lookup Components

The existing community Lookup component has some features that are not yet available in Lookup 3.0, most notably some advanced ways to filter the Lookup values. Since it’s written in older Aura technology instead of Lightning Web Components, it won’t be able to get a custom property editor and we expect Lookup 3.0 to become the community component of choice.

The official Lookup component has the benefit of being a true, supported out-of-the-box solution. It’s on the roadmap to add some of the features of Lookup 3.0 to the official Lookup component.

Install

Version 3.0 unmanaged

View Source

source

Convert Multiselect String Output to a String Collection

Multiselect fields output choices in a semi-colon delimited sting:

apples;oranges;strawberries

Flows often need these strings to be converted into a collection of strings that can be looped over or passed to an action.

The new ConvertToStringCollection builds on the previous ConvertCSVToStringCollection. It lets you pass in a delimiter (a fancy word for “the character that’s used as a separator). So you can pass in ; to get a collection of strings from a multiselect picklist. You can also pass in other popular delimiters like comma and even space.

Inputs

String initialString;

String delimiter;

Outputs

List<String> stringCollection;

This action is available in the new version 1.1 of the String Converter package.

Newly Package-Installable: Formula Builder, Expression Builder, and Formula Evaluator

There is finally a 1-click package install for what may be the most ambitious Flow extension yet.

It starts with a Flow Action called Evaluate Formula that accepts formula strings and evaluates them. You can feed this action with two in-screen builders:

Expression Builder

and Formula Builder

Check it out here.

Get Field Information- Get Fields for an Object

Get Field Information is a simple action that takes the name of an object (e.g. ‘Contact’) and returns information about all of its fields in a collection, including name, label, type, required. The data is returned in a collection of a custom datatype called a FieldDescriptor that can be manipulated declaratively in Flow. That means that you can use the Loop element to loop through the FieldDescriptors and get their information or filter them.

It also means that you can pass the entire collection of FieldDescriptors to a component that expects it, such as the Dual List Box component, which has the ability to take as an input datasource the FieldDescriptor. Here’s how that gets configured:

Install

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

View Source

source

Release History

Unmanaged 1.0 5/17/20

Get Great Multiselect with Dual List Box 2.0

We have a substantial update to the Dual List Box component. It is an enhanced version with custom property editor and requires a Summer ’20 org.

The custom property editor make it easier to configure and highlights the four different types of data sources you can use:

Check it out here.