I am looking to add a custom button to the Account list view that opens a Lightning component. How can I do this?
3 Answers
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
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.
Please let me know if this solution will work for you - it's a nice workaround I have used in the past.
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.
Another approach could be overriding a standard action (like view, new, edit) with your Lightning Component as described here:
Not sure if that fits your use case as overriding will be global and not only triggered from a list view.
-
This will not work for me because the standard layout is overridden by a Lightning record page. Please see (and hopefully answer) this post: salesforce.stackexchange.com/questions/184173/…– Mossi2Commented Jul 13, 2017 at 16:57