Created
February 8, 2019 11:18
-
-
Save simpluslabs/e12b542e8830483aca38f22949fbb475 to your computer and use it in GitHub Desktop.
This file contains 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, track } from 'lwc'; | |
import { ShowToastEvent } from 'lightning/platformShowToastEvent'; | |
import { createRecord } from 'lightning/uiRecordApi'; | |
import { reduceErrors } from 'c/ldsUtils'; | |
import ACCOUNT_OBJECT from '@salesforce/schema/Account'; | |
import NAME_FIELD from '@salesforce/schema/Account.Name'; | |
export default class LdsCreateRecord extends LightningElement { | |
@track accountId; | |
name = ''; | |
onNameChange(event) { | |
this.accountId = undefined; | |
this.name = event.target.value; | |
} | |
createAccount() { | |
const fields = {}; | |
fields[NAME_FIELD.fieldApiName] = this.name; | |
const recordInput = { apiName: ACCOUNT_OBJECT.objectApiName, | |
fields }; | |
createRecord(recordInput) | |
.then(account => { | |
this.accountId = account.id; | |
this.dispatchEvent( | |
new ShowToastEvent({ | |
title: 'Success', | |
message: 'Account created', | |
variant: 'success' | |
}) | |
); | |
}) | |
.catch(error => { | |
this.dispatchEvent( | |
new ShowToastEvent({ | |
title: 'Error creating record', | |
message: reduceErrors(error).join(', '), | |
variant: 'error' | |
}) | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment