-
-
Save pgajek2/1e93f18450586cee69831330133c33c3 to your computer and use it in GitHub Desktop.
Dynamic Function in LWC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { LightningElement } from 'lwc'; | |
| export default class DynamicFunctionInvocation extends LightningElement { | |
| handleDynamicInvocation(recordId) { | |
| const prefixToHandler = { | |
| '001': this.handleAccounts, | |
| '003': this.handleContacts, | |
| '006': this.handleOpportunities, | |
| // ... | |
| }; | |
| const recordPrefix = recordId.substring(0, 3); | |
| if (!prefixToHandler[recordPrefix]) { | |
| throw new Error('Record Type not supported'); | |
| } | |
| prefixToHandler[recordPrefix](recordId); | |
| } | |
| handleAccounts = (recordId) => { | |
| // ... | |
| } | |
| handleContacts = (recordId) => { | |
| // ... | |
| } | |
| handleOpportunities = (recordId) => { | |
| // ... | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment