-
Notifications
You must be signed in to change notification settings - Fork 0
/
novaContaUiRecordApi.js
51 lines (45 loc) · 1.48 KB
/
novaContaUiRecordApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { LightningElement, track } from 'lwc';
import Account from '@salesforce/schema/Account';
import Name from '@salesforce/schema/Account.Name';
import Phone from '@salesforce/schema/Account.Phone';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import { createRecord } from 'lightning/uiRecordApi';
export default class Novaconta extends LightningElement {
account = {
name: "",
phone: ""
};
handleInputChange(event){
let name_ = event.target.name;
let value_ = event.target.value;
this.account = {...this.account, [name_]:value_};
console.log(this.account);
}
createAccount(){
const fields = {};
fields[Name.fieldApiName] = this.account.name;
fields[Phone.fieldApiName] = this.account.phone;
console.log(fields);
const recordInput = {apiName: Account.objectApiName, fields};
console.log(recordInput);
createRecord(recordInput).then(
()=>{
this.dispatchEvent(
new ShowToastEvent({
title:'Sucesso',
message: 'Conta criada'
})
);
}
).catch(
(error)=>{
this.dispatchEvent(
new ShowToastEvent({
title:'Erro',
message: error.body.message
})
);
}
)
}
}