3

I have created an LWC component to do verification of some fields on the current record and want to call the LWC method from a button on the page layout. I tried using LWC inside the lightning component and call that Lightning component from quick action, but it is opening quick action popup, I don't need to open any popup or page, just want to call the LWC method, and based on the result I will show toaster. Also tried the VF page to achieve this but I am not able to achieve this.

Please help.

0

The simplest approach is to implement your LWC so it visually shows a button of its own, have it set isExposed as true in its metadata with appropriate target config to let you add it to Lightning Record Pages of the required object type(s), then add the LWC as a component on the Lightning Record Page itself (using the Lightning App Builder). That way you will see the button and the user can press it to have the record "validated" and the toast raised as needed.

4
  • Thanks Phil. Yes, I know this approach and it is working fine. But the customer wants to call from the page layout button. – Vinit Mehta Oct 29 '20 at 10:34
  • You mean by defining a custom button on the actual page layout? Why? – Phil W Oct 29 '20 at 10:50
  • Yes, I told the same to the client why you need to use the button on-page layout, they said we were using the same functionality in classic and they want in LWC with the same button. – Vinit Mehta Oct 29 '20 at 10:59
  • In this case, why use LWC for the processing? It makes it much harder to support classic (jumping hoops using Lighting-Out etc.) – Phil W Oct 29 '20 at 13:25
0

If you need to use a quick action then you can hide the modal using the following markup. You will also need to automatically close the quick action after the verification is finished.

<aura:component implements="force:lightningQuickAction,force:hasRecordId" >
            <aura:html tag="style">
                .slds-modal {
                  visibility: hidden;
                  display: none;
                }
                .slds-backdrop {
                  display: none;
                }        
            </aura:html>
            <c:yourlwc recordId="{!v.recordId}" onclose="{!c.closeQA}"> </c:yourlwc>
</aura:component>

Add this to your Aura component controller to close the Quick Action. This function can be called from your lwc.

({
    closeQA : function (component, event, helper) {
    $A.get("e.force:closeQuickAction").fire();
  },
})

After the verification has finished you can dispatch an event to close the quick action.

const closeQA = new CustomEvent('close')
this.dispatchEvent(closeQA);
1
  • Thanks Jemat, Yes this is one of the approach but I have to click on that button only, nothing wants to show like a popup or page. If I use this approach and hide that popup in the init method then the popup will appear for a half sec. What they want after clicking on that button it should call the LWC function directly instead of open any popup or page. – Vinit Mehta Oct 29 '20 at 12:03

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.