3

I have created a Lightning Quick Action with a custom aura component to do some async processing over all records. But I cannot find a way to place that button on List View in lightning. I have read other SE articles but that seems few years old. So not sure if it is still not possible.

I know that Custom Button shows up, but then I have to wrap this up in VFpage or create a VF page remote action completely.

Is there a way to display the Action on list view?

4 Answers 4

4

You can't, you still have to use a Visualforce page with standard list controller and pass the records to the aura component using lightning out, as explained in Custom List view buttons in the lightning environment - this feature request is on the roadmap, but I don't know when it will be delivered.

Here you have a sample implementation of how to do it.

10
  • I believe this Spring 21 you can use LWC in your actions still wont have any effect on List view buttons, it would just be as same as its working for now with Aura. Jan 8, 2021 at 10:37
  • Yes, you still have to use a visualforce page, but it's better to use lightning out with LWC than with Aura, hope that makes sense
    – Alba Rivas
    Jan 8, 2021 at 10:42
  • That we can still use right? As the wrapper in both places are VF Page and VF pages can be used to create List view buttons Jan 8, 2021 at 10:44
  • Sorry, now I know what you mean. You can't really use a lightning action with lwc - I messed it up. The options are: 1) vf page with standard list controller for list button + lightning out + aura 2) vf page with standard list controller for list button + lightning out + lwc - Edited the response!
    – Alba Rivas
    Jan 8, 2021 at 11:03
  • @NagendraSingh I know a person who implemented this, and she's kindly shared the code - I've added it to the response. Hope that helps!
    – Alba Rivas
    Jan 8, 2021 at 12:34
2

As another option, you could create a screen Flow and put your aura component there. Then, use the URL of the flow as a URL button.

You'll want to add the lightning:availableForFlowScreens interface and handle ending the flow using availableActions attribute lists.

To get the selected records, there's a couple documents noting the ability to create a collection variable called ids that will store all the record Ids. I do not believe this is officially documented, however.

Unfortunately, like the VF way, this will open a new tab always so you'll have to handle navigating back to the list view if that's your desired behavior.

3
  • Good alternative! I hadn't thought about it. Question: can you pass the selected records to the screen flow somehow? - Not an expert in flow.
    – Alba Rivas
    Jan 8, 2021 at 14:05
  • I definitely mistook the question about related lists vs. list views. I updated it a little. There's a couple documents here and here utilizing a collection variable called ids that stores all the selected records. I would note that this isn't officially documented as a parameter/feature as far as I'm aware even though it does work Jan 8, 2021 at 14:11
  • I'll try it out, thank you!
    – Alba Rivas
    Jan 11, 2021 at 8:40
0

I think I came up with third way - redirect from Visualforce to lightning:isUrlAddressable aura component, see gist here or:

public with sharing class ModalList {
    ApexPages.StandardSetController setCon;
    public PageReference init() {
        List<Id> ids = new List<Id>();
        for (SObject i : this.setCon.getSelected()) {
            ids.add((String)i.get('Id'));
        }
        return new PageReference(
                String.format('/lightning/cmp/c__ModalWrapper?c__ids={0}&c__returnUrl={1}', new String[]{
                        String.join(ids, ','),
                        this.setCon.cancel().getUrl()
                })
        );
    }
    public ModalList(ApexPages.StandardSetController controller) {
        this.setCon = controller;
    }
}
<apex:page
        showHeader="false"
        standardStylesheets="false"
        title="Redirecting"
        standardController="hed__Course_Enrollment__c"
        recordSetVar="leads"
        extensions="PandadocModalList"
        cache="false"
        action="{!init}" />

p.s. you could hack and build base64 encoded link to navigateToComponent event which can open lwc components directly

0

Alba Rivas mentioned the possibility to use Visualforce, Aura Lightning Out app and LWC in the comments. This demonstrates it:

  1. Create Visualforce with its Controller:
public with sharing class ListViewButtonContainerController {
    
    public String selectedIds {get; set;}

    public ListViewButtonContainerController(ApexPages.StandardSetController controller) {
        List<Foo__c> selectedSObjects = (List<Foo__c>) controller.getSelected();
        Set<Id> ids = new Map<Id, Foo__c>(selectedSObjects).keySet();
        selectedIds = String.join(ids, ',');
    }
}
<apex:page standardController="Foo__c" recordSetVar="foos" extensions="ListViewButtonContainerController" lightningStylesheets="true"
standardstylesheets="false" showHeader="false">
    <apex:includeLightning />
    <div id="location" />
    <script>
    $Lightning.use("c:ListViewButtonContainer", function() {
        $Lightning.createComponent(
            "c:listViewButton",
            { "selectedList": '{!selectedIds}' },
            "location",
            function() {});
    });
    </script>
</apex:page>
  1. Create Lightning Out app ListViewButtonContainer in Aura - three lines of markup:
<aura:application extends="ltng:outApp" access="GLOBAL">
    <aura:dependency resource="listViewButton" />
</aura:application>
  1. Create a LWC listViewButton without targets, just Javascript and markup:
<template>
    {selectedList}
</template>
import { LightningElement, api } from 'lwc';

export default class ListViewButton extends LightningElement {

    _selectedList;
    
    @api 
    get selectedList() { return this._selectedList; }

    set selectedList(value) { this._selectedList = value; }
}

This lists the IDs of selected Foo's on a new page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .