Query Records by List of Ids in Flow

One of the big asks for Flow is to be able to have the ability to get Records where the Id is IN a list of Ids. There is an idea on the idea exchange which, at the time of writing this post, has 6,330 points. This is a hot request as many times in the Flow you know the Ids and can create a list of Ids, but you can’t Query based on that list of Ids. Until now.

With Flow Components Winter ’21 release, there is now the ability to query Records where the Id is IN a collection. There is an Apex Action, Get Records WHERE Id is IN List, that makes this possible. In the Flow Apex Action, there are a few pieces to set to ensure you can use the Action. First, the Action needs to know what the Object is for the list of Records that will be returned. When you click into the box, it will give you a list of objects to select from. In the example below, the Contact object was selected. Next, you need to include the Text Collection Variable. This does need to be a Text Collection variable of Ids only. If you’d like to select records from a Related List, check out the Related List Button to Send Records to Flow post. Finally, click the Manually Assign Variables (Advanced) checkbox to set the Record Collection Variable. This should be a variable, type Record, where you are selecting the same Object as the Object that you’re Querying. In the example below, since the Contact object is being queried, the record collection variable is for the Contact object. Make sure that you select the Allow multiple values (collection) checkbox on your variable. The query will return all available fields that the User has access to for the object that you select.

Record Type Picklist and Available Record Types for User in Flow

Getting the available Record Types in the org versus the Record Types a User is allowed might be different. To help this in Flow, a new Apex Action, Get Available Record Types, was added in the Winter ’21 release. This Apex Action will get the available Record Types that the User has access to, including the default record type, to help ensure your User is creating Records using Record Types they are allowed to use, with ease. Additionally, there is a Lightning Component, Record Type Picklist, that will allow you to easily show the Record Types to User and use the selected Record Type later in the Flow.

First, take a look at the Apex Action, Get Available Record Types. In the example below, we are looking up the available Account Record Types for the User. To do this, you first enter the Object API Name, in this instance, Account. You will need to click the box, Manually assign variables (advanced) so that you can set your variables appropriately. Then, you need to have a text Variable to store the default Record Type Id for the User. Finally, you need to have a collection Variable, type of Object, where the Object is Record Type, to store the full list of Record Types available for the User. See second screenshot for an example.

After you run the Get Available Record Types Apex Action, you then can use the Record Type Picklist Lightning Component in a screen to allow your Users to select the record type they would like to use. As you can see in the example below, you use the default record type id as the Default Value / Selected Value and you use the Record Type collection variable as the Picklist Values. Additionally, it is recommended to click the Manually Assign Variables (Advanced) and use a text variable to store the Id of the Record Type that the User selected in the Default Value / Selected Value. You can then use this text variable as the Record Type Id in any record that you’re creating.

Run Flow Button Updates – Winter ’21

With the Winter ’21 Flow Components update, the Run Flow button is now available from:

Home Screen

Experience Builder (formerly Salesforce Community Cloud)

When redirecting from a community button to a record, the URL structure for communities is different than lightning or classic. To redirect in communities, redirect to a URL and ensure that you start the URL with “/detail/” followed by the Id that you’re looking to redirect to. Example screen shot is below, where {!Create_Account} is the Id of the Account that was created in the Flow.

Call Flow in Lightning Runtime through a URL

Calling a Flow from a button through a URL link has been something that has been available in Salesforce for a while now. Using the URL runs the Flow in classic mode, but you can extend to Lightning through Enabling Lightning Runtime for Flows. This, however, does not work with the Lightning Navigation Service, and as a result, the ability redirect the Flow to a record that was created inside of the Flow or control the navigation is not easily done.

With Flow Components Winter 21 release, we’ve created a Lightning Component that you can call via URL that will start your Flow. As it is a Lightning component, it works with the Lightning Navigation Service, allowing you to be able to use the Flow Components Redirect to Id or Redirect to URL.

In order to call the Flow, you create a button like the one below, where recordId is the recordId you want to pass in and flowName is the name of the Flow.


Additionally, in your Flow, even if it is not used, you need a variable, named ids, that will allow for input. The variable should be a text input variable and it can be a multiple records input, like the one for the Related List Button.

Without this variable, you might see an error message similar to the below error message.

And that’s it. Now you can use Flow Components Redirect to Id or Redirect to URL with your URL launched Flow.

Related List Button to Send Records to Flow

With the Winter 21 release we have added the capability to select records in a related list and send the records to Flow!  This is a big enhancement that we think many will find great uses for.  There are a few pieces of setup.  To help with understanding of how this works, we’re gong to create a button on the Contact related list from an Account Page to be able to send selected Contacts to a Flow.

First, you’ll need to work with the Related List Type of Enhanced List.  This will allow you to select multiple records in the related list.

Next, you’ll need to create a VERY small Visualforce Page.  You might be asking why.  Well, in a very technical description, we’re using the functionality in the standard controller on an object to do our work.  For those less technical, Salesforce has capabilities in a Visualforce Page that allows us to send the selected record to it.  But don’t worry, the Visualforce Page is going to redirect to your Flow with the records you selected!

Below is the screen shot of the Visualforce Page.  The syntax will always be the same, but you’ll be setting the StandardController part of the page to be what your object name is, whether it is Account, Contact, or Custom_Object__c, you need the API name of your object of the related list.  I’ve highlighted the part that you need to update to use with your object.  In the example below, we’re using the standard Contact object, so we’re going to be selecting multiple Contacts.  Just replace it with your object API name.

Ensure that your users have access to the redirectToFlow Apex Class in profiles/permissions, as that is what does the magic.

Once you have your Visualforce Page, you need to create the button.  There’s two parts to the button that you need to consider.  First, what is the object your related list is part of.  In our example, this is the Contact.  Second, you’ll need to know what the object is that is displaying your related list, in this example, the Account.  This is important as we send information to the Flow.  There are two variables that need to be added to the Flow.  First, is the recordId.  In our example, that would be the Account, as that is the “launching” object that we are clicking the button from.  In your Flow, you need a text variable named recordId (spelled exactly like that) that you’ll send the main record to that allows for input.

Second, you’ll need a variable named ids (spelled exactly like that) that is a text variable which allows for multiple values, available for input.  Example below.

Now, for the button, the ids you’re sending into are the Contact records, and the main record that you’re sending in is the Account.  So, you need a button on the Contact object like below.  I’ll break down the button after.

The first part is that this is a formula button using the URLFOR formula.  You’ll be using “/apex/” as the start and the API name of your Visualforce Page as the second part.  Since our example uses a Visualforce Page named “Contacts_To_Flow”, we’ll have our first part of the URLFOR formula be “/apex/Contacts_To_Flow”.  After that, you’re not using the “standard” Id, so write null.  The next part is where you define your Flow and the “launching” object Id.  So, we put this in brackets.  First, “flowName” spelled just like that is what is needed to set the name of the Flow.  Then, an equals sign, and the API name of your Flow.  In this example, I’m using “flowName=”Show_Contacts””.  Put a comma after that as you are defining a new parameter, and here you can set “recordId” as the record Id of the “launching” object.  This is important.  In the example, we’re using Account.Id.  This is because the button is being launching from the Account, so you’re sending the Account Id to the flow as the record Id.  It should be written like “recordId=Account.Id”.  Notice that in the first part, flowName, you need to put quotation marks around the API name of the Flow, but those are not used in the object Id part.

Your button should be a List Button where Display Checkboxes (for Multi-Record Selection) is checked.

And that’s it for your button!  The last part is inside your flow.

Since the Visualforce Page just sends in record Ids, and not the actual records, there is a new Action in Flow Components to be able to get the records from the Ids.  First, you’ll need to create a new Variable, data type of Record, which allows multiple values, and set it to the object of the ids.  In this example, Contact is the object.  Below is an example of the variable.

After that, grab the Action from Interaction on the Flow Canvas and find the Get Records WHERE Id is IN List.  You’ll send in the ids variable that was created earlier and manually assign variables, setting the Record Collection Variable with the variable you just created for the records.  Example screen shot below.

And that’s it!  Now the records that your user selects in the related list will be available in the Record Collection Variable for you to use within the Flow!

Want to get all the field values and a full collection of records? Check out the Query Records by List of Ids in Flow post to see how to do it!

Flow Components – Winter ’21

There are a few new exciting things coming to Flow Components in our Winter ’21 release! We’ve created a lightning component which allows you to call a flow via a URL, which means that you can use this with Lightning Runtime. Additionally, it works with related lists in records where you can select multiple records to send to a flow, using a very small visualforce page. And one of our favorites, the ability to query records using the SOQL “IN” condition where the Ids are in a collection variable. We hope you’re as excited for this release as us!

Related List Button to Send Records To Flow

Call Flow in Lightning Runtime through a URL

Run Flow Button Updates – Launch from Experience Builder (Formerly Communities), Home and Utility Bar

Record Type Picklist and Available Record Types for User in Flow

Query Records by List of Ids in Flow

Flow Components – Unlock Record

Flow Components come with the ability to unlock a record through a Flow Action. There are two inputs to the Unlock Record Action. The first is the Unlock Record Id, or the Id of the record that you would like to unlock. The second is System Unlock which is a Boolean of True or False, defaulted to False.

The Unlock Record Flow Action runs in user mode without any additional setup. This means that a User who does not have the ability to unlock the record will not be able to. There is the ability for an admin to configure Flow Components to run in System Mode.

Even if the System Unlock Input Value is set to true, it will not necessarily run in System Mode. This is to ensure that a User has explicit permission to be able to use the Unlock Record in System Mode.

The Flow Component package comes with a Custom Permission, Enable Unlock Record In System Mode. This Custom Permission is required in addition to the Unlock Record Action to be set to True. The Custom Permission can be added to a Profile, a Permission Set, or the Permission Set that comes with Flow Components can be assigned to the User, which is also named Enable Unlock Record In System Mode. These two things together are required for the Flow to run in System Mode.

Get Available Record Types

Creating multiple Quick Actions for each Record Type means getting a lot of buttons on a page layout. Trying to create this in Flow can streamline the number of buttons down to 1. You can’t show all record types, however, as if a User selects a record type they don’t have access to, things break.

The Get Available Record Types Apex Action will allow you to check a User’s permissions with Record Types on a given object. Simply enter select the Get Available Record Types Apex action.

Then select the object that you want to retrieve the Record Types for.

And set the output of those records to a Record Variable that allows for multiple values with the Object type of Record Type.

You can also get the Default Record Type Id in a Text Variable.

Simply choose them in the output of the Apex Action.

And you can easily assign the default Record Type in your Flow!

NOTE: As of right now, this Apex Action has the main function of getting the Default Record Type. There is a Lightning Component that has been built that will allow you to display the Record Type List to the User, however there is a current Salesforce bug that is preventing this from being able to be added to the Flow Components package.
https://success.salesforce.com/issues_view?id=a1p3A000000BMPtQAO Once this is resolved, we will update the package with the Record Type Picklist Lightning Component that will allow you to easily have users select the Record Type of the record they would like to create with the results of the Get Available Record Types Apex Action.

Locked Record Notifier

Being able to lock and unlock records is very helpful for ensuring data integrity. In Salesforce Classic, there used to be a lock icon to let you know when a record was locked.

This hasn’t made it over to Lightning as of yet. As a result, you can use the Locked Record Notifier to let Users know that the record is locked and in addition, you can use your own note.

Simply go to Lightning App Builder, select the Locked Record Notifier, drag it to where you would like it to show, and enter some text. If the record is unlocked during the Lightning App Builder Page edit, you’ll see it blank, like below, as the Locked Record Notifier will not show unless a record is locked.

If the record is locked during the Lightning App Builder Page edit, you’ll be able to see the preview.

The component will automatically show if the record is locked and will not show if the record is unlocked. This is a great way to let your users know a record is locked, and give them additional information if needed!

Lock Record

Salesforce Approvals are a great feature that allow you to be able to track approvals and lock records from having any changes after approvals. Sometimes, however, an Approval Process doesn’t fit into the situation that you’re trying to create. You know how to create a custom approval process to achieve the process part of it, but since you’re not using the standard Salesforce Approval Process, you can’t lock the record.

With the Lock Record Apex Action, you can now lock that record.

Use the Lock Record Apex Action with Process Builder to automatically lock a record based on something like, the status going to Approved.

Additionally, you can use Flow and the Apex Actions in Flow to lock a record.

A simple Flow will allow you to lock a record, or add your custom logic to lock the record only after it has gone through a custom approval.

NOTE: Unlike the Unlock Record Apex Action, any user who has edit rights on a record will be able to lock the record. This means that you can lock a record from a Flow button without having to use Process Builder.