You need to sign in to do that
Don't have an account?

Get leads in input fields
Hi!
I have leadtable as in the image

I need get leads in input fields to save them automatically. In inputs, it is necessary to simultaneously receive leads from the database and change them with saving. They should be saved when you change something. When entering the new value of the field this value should be saved in the database automatically (user should not click on some button). Please tell me how can I do that.
My code.
Html
<template>
<lightning-card title="Leads">
<lightning-layout>
<lightning-layout-item>
<lightning-record-edit-form object-api-name="Lead">
<lightning-input-field field-name={Name}></lightning-input-field>
<lightning-input-field field-name={Title}></lightning-input-field>
<lightning-input-field field-name={Phone}></lightning-input-field>
<!-- <lightning-input-field field-name="Title"> </lightning-input-field>
<lightning-input-field field-name="Title"> </lightning-input-field> -->
</lightning-record-edit-form>
<!-- <lightning-layout-item size="12" padding="around-small">
<lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
</lightning-layout-item> -->
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
Js
import { LightningElement, wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
import NAME_FIELD from '@salesforce/schema/Lead.Title';
import TITLE_FIELD from '@salesforce/schema/Lead.Title';
import PHONE_FIELD from '@salesforce/schema/Lead.Phone';
// const columns = [
// { label: 'Name', fieldName: 'recordLink', type: 'url',
// typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
// { label: 'Title', fieldName: 'Title', type: 'text', editable: true },
// { label: 'Phone', fieldName: 'Phone', type: 'text', editable: true }
// ];
export default class LeadTable extends LightningElement {
leadTitle = NAME_FIELD;
leadTitle = TITLE_FIELD;
leadPhone = PHONE_FIELD;
// columns = columns;
// leads;
@wire(getLeads)
wiredLeads(value) {
const {error, data} = value;
if (data) {
let leadData = JSON.parse(JSON.stringify(data));
leadData.forEach(record => {
record.recordLink = "/" + record.Id;
record.LeadName = record.Name;
});
this.leads = leadData;
} else if (error) {
this.error = error;
}
}
}
Apex
public with sharing class Leads {
@AuraEnabled(cacheable=true)
public static List<Lead> getLeads() {
List<Lead> leads = [
SELECT Id, Name, Title, Phone
FROM Lead
Limit 3
];
System.debug('leads = ' + leads);
return leads;
}
}
I have leadtable as in the image
I need get leads in input fields to save them automatically. In inputs, it is necessary to simultaneously receive leads from the database and change them with saving. They should be saved when you change something. When entering the new value of the field this value should be saved in the database automatically (user should not click on some button). Please tell me how can I do that.
My code.
Html
<template>
<lightning-card title="Leads">
<lightning-layout>
<lightning-layout-item>
<lightning-record-edit-form object-api-name="Lead">
<lightning-input-field field-name={Name}></lightning-input-field>
<lightning-input-field field-name={Title}></lightning-input-field>
<lightning-input-field field-name={Phone}></lightning-input-field>
<!-- <lightning-input-field field-name="Title"> </lightning-input-field>
<lightning-input-field field-name="Title"> </lightning-input-field> -->
</lightning-record-edit-form>
<!-- <lightning-layout-item size="12" padding="around-small">
<lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
</lightning-layout-item> -->
</lightning-layout-item>
</lightning-layout>
</lightning-card>
</template>
Js
import { LightningElement, wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
import NAME_FIELD from '@salesforce/schema/Lead.Title';
import TITLE_FIELD from '@salesforce/schema/Lead.Title';
import PHONE_FIELD from '@salesforce/schema/Lead.Phone';
// const columns = [
// { label: 'Name', fieldName: 'recordLink', type: 'url',
// typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
// { label: 'Title', fieldName: 'Title', type: 'text', editable: true },
// { label: 'Phone', fieldName: 'Phone', type: 'text', editable: true }
// ];
export default class LeadTable extends LightningElement {
leadTitle = NAME_FIELD;
leadTitle = TITLE_FIELD;
leadPhone = PHONE_FIELD;
// columns = columns;
// leads;
@wire(getLeads)
wiredLeads(value) {
const {error, data} = value;
if (data) {
let leadData = JSON.parse(JSON.stringify(data));
leadData.forEach(record => {
record.recordLink = "/" + record.Id;
record.LeadName = record.Name;
});
this.leads = leadData;
} else if (error) {
this.error = error;
}
}
}
Apex
public with sharing class Leads {
@AuraEnabled(cacheable=true)
public static List<Lead> getLeads() {
List<Lead> leads = [
SELECT Id, Name, Title, Phone
FROM Lead
Limit 3
];
System.debug('leads = ' + leads);
return leads;
}
}
Hey Mike,
Check this link if it help :-
https://developer.salesforce.com/forums/?id=9062I000000XqrLQAS
Regards,
Priya Ranjan