0

How can I call lightning component from custom button on record page?

I'm trying to call lightning component when I click custom button, but I cannot do it.

How should I set the values to make a new custom button, especially in "Behavior"?

Here's the screenshot:

enter image description here

1
  • 1
    no, you just cannot. Consider using action rather than button, – Wayne Ni Jan 7 '20 at 5:53
2

As Charles T. on this post answered:

Create a Lightning Component that implements lightning:isUrlAddressable and create a link button that navigates to that component's Lightning URL, passing enough parameters to have the info you need (record ID for example). This will show full-screen rather than as a modal. Also note that the component will have to handle changes to v.pageReference to ensure it behaves correctly if a user navigates to it a second time in the same session.

Consequently, contrary to what Manish Anand says above, you don't have to embed the Lightning Component in a Lightning App. In fact, you can call Lightning Components not just from record detail buttons but also list buttons. Personally, I call lightning:isUrlAddressable Lightning Components constantly from related lists to navigate to subtabs with Lightning Component child object tables for easier management of child records. See the list button example below with two parameters passed in.

Button or Link URL:
/lightning/cmp/c__ContactInformationManager?c__recordId={!Contact.Id}&c__origin="Contact"
Display Checkboxes (for Multi-Record Selection): false

For instructions on how to use lightning:isUrlAddressable and pageReference, see here.

0

You can call a lightning app on click of a Detail Page Button and embed your lightning component in the lightning app. Try using something like below in the Button or Link URL value

/c/OpptyProductDuplicateApp.app?recid={!Opportunity.Id}

Here recid is the attribute of the lightning app - OpptyProductDuplicateApp , which will hold the record Id.

Alternatively, you can call a visualforce page on a click of a button and embed your lightning component in the visualforce page. Embed lightning component in VF page

-2

You cannot call lightning component from Button or Link. Instead you can create an Action and can be added to "Salesforce Mobile and Lightning Experience Actions" section in the page layout. Also make sure to include force:lightningQuickAction interface to the lightning component

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.