{"id":13545924,"url":"https://github.com/andrii-solokh/LWCAction","last_synced_at":"2025-04-02T17:32:24.378Z","repository":{"id":159724783,"uuid":"275160906","full_name":"andrii-solokh/LWCAction","owner":"andrii-solokh","description":"LWC as Lightning Action. Dynamically create LWC depending on Lighting Action API Name.","archived":false,"fork":false,"pushed_at":"2021-12-23T21:30:35.000Z","size":1808,"stargazers_count":14,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-03T14:34:48.952Z","etag":null,"topics":["aura","aura-component","lightning-action","lwc","lwc-component","salesforce","salesforce-developers","salesforce-lightning","sfdc","sfdc-deployment"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrii-solokh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["andrii-solokh"]}},"created_at":"2020-06-26T13:19:59.000Z","updated_at":"2023-04-26T20:24:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1a22747-8f9b-4727-9724-42fc9b880c59","html_url":"https://github.com/andrii-solokh/LWCAction","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrii-solokh%2FLWCAction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrii-solokh%2FLWCAction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrii-solokh%2FLWCAction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrii-solokh%2FLWCAction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrii-solokh","download_url":"https://codeload.github.com/andrii-solokh/LWCAction/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246860223,"owners_count":20845630,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aura","aura-component","lightning-action","lwc","lwc-component","salesforce","salesforce-developers","salesforce-lightning","sfdc","sfdc-deployment"],"created_at":"2024-08-01T12:00:27.055Z","updated_at":"2025-04-02T17:32:23.655Z","avatar_url":"https://github.com/andrii-solokh.png","language":"JavaScript","funding_links":["https://github.com/sponsors/andrii-solokh"],"categories":["On Platform Community Repos"],"sub_categories":[],"readme":"⚡ IMPORTANT ⚡\n==========================\n\nDue to Summer '21 release, LWC is now natively available as Quick Action.\n\n\u003cbr/\u003e\n\n\u003ca href=\"https://githubsfdeploy.herokuapp.com\"\u003e\n  \u003cimg alt=\"Deploy to Salesforce\"\n       src=\"https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png\"\u003e\n\u003c/a\u003e\n\n# LWCAction\n\nTo use LWC as Lightning Action we need to wrap it with Aura Component. Instead of creating new unnecessary Aura Components, coding close Lightning Action event handlers and adding spinners, we can create generic Aura Component which will dynamically create LWC depending on Lighting Action API Name.\n\n![](demo.gif)\n\n### Sample code\n\nhttps://github.com/andrii-solokh/LWCAction-samplecode\n\n### How to use\n\n1. In LWC component's '.js-meta.xml' file update 'isExposed' field:\n\n```\n\u003cisExposed\u003etrue\u003c/isExposed\u003e\n```\n\n2. Lightning Action should invoke Aura Component 'LWCLightningAction'.\n3. Lightning Action API Name should be the same as LWC API Name. I can advise naming LWC as 'SObjectName + ActionName + Action', example: 'quoteApplyDiscountAction'.\n4. LWC should extend 'LwcAction':\n\n```\nimport LwcAction from 'c/lwcAction'\nexport default class QuoteApplyDiscountAction extends LwcAction {}\n```\n\n5. Stop spinner when LWC is ready:\n\n```\nthis.ready()\n```\n\n### Features\n\n- Closing action from LWC:\n\n```\nthis.closeAction()\n```\n\nFrom template '{closeAction}' accordingly:\n\n```\n\u003clightning-button label=\"Close\" onclick={closeAction}\u003e\u003c/lightning-button\u003e\n```\n\n- Show spinner:\n\n```\nthis.showSpinner()\n```\n\n- Hide spinner:\n\n```\nthis.hideSpinner()\n```\n\n- Refresh view:\n\n```\nthis.refreshView()\n```\n\n- Fire any Aura Event, 'this.fireAuraEvent(eventName, params):\n\n```\nthis.fireAuraEvent('e.force:createRecord', { entityApiName: \"Contact\" })\n```\n\n- Id and sObject name of Record from which Lighting Action was invoked is passed to LWC and can be accessed with:\n\n```\nthis.recordId\nthis.sObjectName\n```\n\n### Actions not in LwcAction context\n\n- To close action, show or hide spinner from component other than LwcAction:\n\n1. Import 'LwcAction':\n\n```\nimport LwcAction from'c/lwcAction'\n```\n\n2. Invoke required method:\n\n```\nLwcAction.fireCloseAction(this) // close Lighting Action\nLwcAction.fireShowSpinner(this) // show spinner\nLwcAction.fireHideSpinner(this) // hide spinner\nLwcAction.fireRefreshView(this) // refresh view\nLwcAction.fireAuraEvent(this, 'e.force:createRecord', { entityApiName: \"Contact\" }) // call any Aura event with params\n```\n\n### Additional Features\n\n- You can keep component hidden until it's ready to be presented by wrapping it with:\n\n```\n\u003ctemplate if:true={isReady}\u003e\u003c/template\u003e\n```\n\nExample:\n\n```\n\u003ctemplate\u003e\n  \u003ctemplate if:true={isReady}\u003e\n    \u003cdiv\u003eYour component\u003c/div\u003e\n  \u003c/template\u003e\n\u003ctemplate\u003e\n```\n\nPresent LWC and hide spinner call:\n\n```\nthis.ready()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrii-solokh%2FLWCAction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrii-solokh%2FLWCAction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrii-solokh%2FLWCAction/lists"}