{"id":6620,"date":"2024-02-16T06:06:00","date_gmt":"2024-02-16T06:06:00","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=6620"},"modified":"2025-09-23T12:11:23","modified_gmt":"2025-09-23T12:11:23","slug":"how-to-invoke-an-lwc-component-function-from-aura-component","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2024\/02\/16\/how-to-invoke-an-lwc-component-function-from-aura-component\/","title":{"rendered":"How to Invoke an LWC Component Function from Aura Component"},"content":{"rendered":"\n<p>This blog\u00a0explains how to call a LWC component function from an Aura component when an Aura event takes place.<\/p>\n\n\n\n<h4 class=\"wp-block-heading has-black-color has-text-color has-link-color wp-elements-d3bd10051f6799d1b7d4d9446e622ef5\"><strong>To invoke an LWC function from an Aura component, follow these steps:<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Declare the LWC component function as <strong>public<\/strong> by using the <strong><code>@api<\/code> decorator<\/strong>.<\/li>\n\n\n\n<li>Access the LWC component from the Aura component using <code><strong>aura:id<\/strong><\/code><\/li>\n<\/ul>\n\n\n\n<p>The example below features a Lightning button labeled <strong>&#8220;Call LWC Function&#8221;<\/strong>. When clicked, it calls the LWC component function and displays the message: <strong>&#8220;LWC Function Invoked through Aura Component.&#8221;<\/strong><\/p>\n\n\n\n<p>The following code is for the LWC component that displays text when invoked by the Aura component.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">LWCComponent.html<\/mark><\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e6e6e6\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-black-color\">&lt;template>  \n   &lt;div class=\"slds-box\">  \n      &lt;div if:true={DisplayText}>{textValue}&lt;\/div> \n   &lt;\/div>  \n &lt;\/template><\/mark><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">LWCComponent.js<\/mark><\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e6e6e6\"><code>import { LightningElement, track, api } from 'lwc';  \n export default class lWCComponent extends LightningElement\n{  \n  DisplayText = false;\n  textValue='LWC Function Invoked through Aura Component'  \n  @api LWCFunction()\n  {\n    this.DisplayText = true; \n  }\n}<\/code><\/pre>\n\n\n\n<p>The following code is the Aura Component to call the above LWC component on a button click.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">AuraComp.cmp<\/mark><\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e6e6e6\"><code>&lt;aura:component implements=\"force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction\" access=\"global\" &gt;  \n  &lt;div class=\"slds-box\"&gt;\n     &lt;lightning:button variant=\"brand\" label=\"Call LWC Function\" onclick=\"{! c.handleClick }\" \/&gt;  \n   &lt;\/div&gt;  \n   &lt;c:lWCComponent2 aura:id=\"lWCComponent2\"&gt;&lt;\/c:lWCComponent2&gt;  \n&lt;\/aura:component&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">AuraCompController.js<\/mark><\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code has-background\" style=\"background-color:#e6e6e6\"><code>({  \n  handleClick : function(component, event, helper) \n    {  \n      component.find('lWCComponent2').LWCFunction ();   \n    }  \n})<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Output:<\/mark><\/strong><\/h2>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2022\/02\/1.Before-Invoking-LWC.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2022\/02\/1.Before-Invoking-LWC.png\" alt=\"Before Invoking LWC\"><\/a><\/center>\n<font size=\"2\"><center><i>Before Invoking LWC<\/i><\/center><\/font>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2022\/02\/2.After-Invoking-LWC.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2022\/02\/2.After-Invoking-LWC.png\" alt=\"Invoke an LWC Component function from Aura Component\"><\/a><\/center>\n<font size=\"2\"><center><i>Invoke an LWC Component function from Aura Component<\/i><\/center><\/font>\n\n\n\n<p>The above steps shows how user can fetch the current record Id from <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/\">Salesforce<\/a> using LWC.<\/p>\n\n\n\n<p>We hope that you find this blog helpful, if you still have queries, don\u2019t hesitate to contact us at&nbsp;<a href=\"mailto:na.sales@greytrix.com\" target=\"_blank\" rel=\"noreferrer noopener\">salesforce@greytrix.com<\/a>.<\/p>\n\n\n\n<p style=\"text-align: justify\"><b>About Us<\/b><\/br>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> \u2013 a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.<br><br> Greytrix has some unique solutions for Cloud CRM such as <a href=\"\">Salesforce Sage integration<\/a> for <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/integration\/\">Sage X3<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-100-integration\/\">Sage 100<\/a> and <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-300-integration\/\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/data-migration-support\/\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Integrated App development<\/a>, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star rated app listed on <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<br> The GUMU&#x2122; Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.<br><br> For more information on our Salesforce products and services, contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n\n\n\n<p><strong>Related Posts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2022\/02\/14\/how-to-create-multi-select-pick-list-field-using-lightning-web-component\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2022\/02\/14\/how-to-create-multi-select-pick-list-field-using-lightning-web-component\/\" rel=\"noreferrer noopener\">How to Create Multi-Select Pick-list Field Using Lightning Web Component<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2022\/01\/31\/how-to-call-the-apex-method-in-lightning-web-component\/\" data-type=\"URL\" data-id=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2022\/01\/31\/how-to-call-the-apex-method-in-lightning-web-component\/\" target=\"_blank\" rel=\"noreferrer noopener\">Call the apex method in lightning web component<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2022\/01\/17\/how-to-create-records-from-apex-restful-service-in-salesforce\/\" target=\"_blank\" rel=\"noreferrer noopener\" data-type=\"URL\" data-id=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2022\/01\/17\/how-to-create-records-from-apex-restful-service-in-salesforce\/\">Create records from Apex Restful Service in Salesforce<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/08\/16\/clone-record-of-any-object-using-flows-in-salesforce\/\" data-type=\"URL\" data-id=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2021\/08\/16\/clone-record-of-any-object-using-flows-in-salesforce\/\" target=\"_blank\" rel=\"noreferrer noopener\">Clone Record of Any Object using Flows in Salesforce<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This blog\u00a0explains how to call a LWC component function from an Aura component when an Aura event takes place. To invoke an LWC function from an Aura component, follow these steps: The example below features a Lightning button labeled &#8220;Call LWC Function&#8221;. When clicked, it calls the LWC component function and displays the message: &#8220;LWC\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2024\/02\/16\/how-to-invoke-an-lwc-component-function-from-aura-component\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1266,1131,1267,1068,206,1055,1069,207,208,1050,1049,651],"class_list":["post-6620","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-api-decorator","tag-aura","tag-aura-component","tag-aura-method","tag-lightning","tag-lightning-aura-component","tag-lightning-aura-method","tag-lightning-basics","tag-lightning-component","tag-lightning-web-component","tag-lwc","tag-salesforce-lightning-component"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=6620"}],"version-history":[{"count":15,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6620\/revisions"}],"predecessor-version":[{"id":11524,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/6620\/revisions\/11524"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=6620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=6620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=6620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}