1

I am looking to add a custom button to the Account list view that opens a Lightning component. How can I do this?

2

Bhawna is correct, you cannot call a Lightning Component from a List button directly. In the past, I have implemented something which may be useful in this scenario.

Step 1: Create the component you want and make it implement the lightning:isUrlAddressable interface

<aura:component implements="flexipage:availableForAllPageTypes,force:appHostable,lightning:isUrlAddressable" access="global">
<aura:handler name="init" value="{!this}" action="{!c.initialize}" />
<div class="slds-box slds-theme_default">
    Some Stuff Here
</div>

({
    initialize : function(component, event, helper) {
        var recordId = component.get("v.pageReference").state.c__id;
        console.log('Here is record Id' + JSON.stringify(recordId));
    }
})

Step 2: Create a Hyperlink Formula field on Account.

HYPERLINK("/lightning/cmp/c__myComponent?c__id=" + Id, "Click Me!","_self"))

Step 3: Add formula field to list view enter image description here

Now you can do whatever you need to do with your component and the record Id passed to it - in this scenario, we are just logging it to the console. enter image description here

Please let me know if this solution will work for you - it's a nice workaround I have used in the past.

| improve this answer | |
1

Another approach could be overriding a standard action (like view, new, edit) with your Lightning Component as described here:

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_lex_s1_action_overrides.htm

Not sure if that fits your use case as overriding will be global and not only triggered from a list view.

| improve this answer | |
0

You can not call a Lightning Component from List Button directly. You need to do it using visual force page. You can check the Component developer guide for this. Complete solution is given there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.