How to use Lightning Flow as List View in Salesforce?

on

|

views

and

comments

Hello #Trailblazer,

Welcome back, In this blog post we will see how to use a lightning flow as a list view button inside salesforce for any object.

Use Case

Create a Flow which will act as List View Button on Lead Object and when a user selects multiple records and clicks on our custom button “Convert Lead” then it should convert all the Selected Lead Records and Navigate back to Lead Object List View.

Implementations

As we know that we can not use flow directly in a ListView button, we will use an intermediate flow which will include the flow inside the VF page.

So in order to implement the solution, we will follow the below steps

  1. Create an Apex Class which will have an Invocable method to convert the Lead
  2. Create an Screen Flow which will call the Invocable Apex and pass the required parameters inside the invocable apex
  3. Create another Apex Class which will act as an Extensions of the VF page which will give us the record ids of the selected records and also the selected records with the fields which we want to display over screen.
  4. Create the VisualForce Page which will have the Flow inside it and also will pass the required parameters to Salesforce Lightning Flow
  5. Create the List View button and add it to Lead Search Layout
  6. Test the button

Step1 – Create the Apex Class with Invocable Method

The very first step is to create an apex class which have an Invocable method inside it to convert the lead. Below is the code which we will be using for the demo.

Step2 – Create the Screen Flow

Now, as we have created the helper class with an Invocable Apex Method, time is to create the Flow

  1. Login to Salesforce
  2. Go to Setup
  3. In the Quick Find box search for Flows
  4. Select Flows
  5. Click on New Flow button
  6. Once the Screen Pop-up Select Screen Flows
  1. Click on + icon
  2. Select Screen Component
  3. Provide the Label and API Name will be auto populated
  4. Add the Display Text Component to the Screen with the given message “Click Next to convert the selected lead records.”
  1. Click on “New Resource” From the left side bar
  2. For the resource type select variable
  3. For the API Name give “varLeadRecordIds”
  4. For the Data Type select “Text”
  5. Check “Allow multiple values (collection)” checkbox
  6. Check “Available for input” checkbox
  1. Click on “New Resource” From the left side bar
  2. For the resource type select variable
  3. For the API Name give “vaLeadRecords”
  4. For the Data Type select “Record”
  5. For Object select Lead
  6. Check “Allow multiple values (collection)” checkbox
  7. Check “Available for input” checkbox
  1. Click on + Icon again
  2. Select Action from the available icons
  3. Search for “Custom Lead Convert” and select that action

Save and Activate the flow

Step3 – Create VF Page Extension Class

This Apex Class will be responsible for getting all the selected lead records and then preparing the public variables which we will be passing to the flow as an input. “VE_AutoLeadController” use this as the name of your Apex Class and get the code from below Gist.

Step4 – Create VF Page

The VF Page will use “VE_AutoLeadController” Apex class as an Extension and “Lead” as standard object because we will use this VF page for Lead Object List View. Page will also have the Flow inside itself

To use the flow inside VF page we use a special tag which is “flow:interview“, this tag requires min 1 variable which is the API Name of our Salesforce Flow. We can also pass the variables from VF to flow. Learn more about “flow:interview” tag. Use below code for the same

Step5 – Create List View Button

Now, as we have developed all the components, the time is to create a list view button and add it to the list view. To Create the Button follow the below instructions.

  1. From the Setup –> Go to Object Manager
  2. Search for Leads
  3. Click on “Button Links, and Actions
  4. Select “New Button or Link
  5. Create the Button based on the Below Configuration

Step6 – Add the button to Search Layout

Follow the below steps to add the button to page layout

  1. From the Same Lead Object Page, Click on the “Search Layouts for Salesforce Classic
  2. Click dropdown next to “List View” and then Click on Edit
  3. Add your buttons from the “Available Buttons” to “Selected Buttons” Section
  4. Save the Changes

Step7 – Test the buttons

From the Lead Tab, Select “All Open Leads“, Select Multiple Records and then Click on your Custom Button

Final Video

Thanks for reading 🙂 Happy #Trailblazing

Amit Singh
Amit Singhhttps://www.pantherschools.com/
Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion
Share this

Leave a review

Excellent

SUBSCRIBE-US

Book a 1:1 Call

Must-read

How to start your AI Journey?

Table of Contents Introduction Are you tired of the same old world? Do you dream of painting landscapes with your code, composing symphonies with data, or...

The Secret Weapon: Prompt Engineering: 🪄

Table of Contents Introduction Crafting the perfect prompt is like whispering secret instructions to your AI muse. But there's no one-size-fits-all approach! Exploring different types of...

How to Singup for your own Production org?

Let's see how we can have our salesforce enterprise Salesforce Org for a 30-day Trial and use it as a Production environment. With the...

Recent articles

More like this

2 COMMENTS

  1. Hi Amit,

    Is it possible to skip the VF page here? Actually I don’t want to redirect page from the ListView. I just want to add one button at ListView and on click “Lead Convert” then display show message (Success/Error).

    Regards,
    Puneet

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5/5

Stuck in coding limbo?

Our courses unlock your tech potential