You need to sign in to do that
Don't have an account?
Saurabh Bisht 19
create a contact record with custom lookup field in salesforce lwc
please code it in LWC with html,css,js and apex class looklup field is Account in Contact
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
please put your full requirement what exactly you want after that may be I can help you
thank you
lastname
Account
these 3 field i need in my components form
-------------------------------------------------Html file ----------------------------------------------------------------------
<template>
<div>
<div class="slds-p-around_medium lgc-bg">
<lightning-input type="text" label="first name" onchange={firstNames}></lightning-input>
</div>
<div class="slds-p-around_medium lgc-bg">
<lightning-input type="text" label="lastname" onchange={lastNames}></lightning-input>
</div>
<div class="slds-p-around_medium lgc-bg">
<lightning-combobox
name="progress"
label="Account"
value={value}
placeholder="Select Progress"
options={options}
onchange={handleChange} ></lightning-combobox>
</div>
<lightning-button label="submit" onclick={createContact}> </lightning-button>
</div>
</template>
----------------------------------------------------------------------------------------js File-------------------------------------------------------------------------------
import { LightningElement } from 'lwc';
import getallAccount from '@salesforce/apex/CreateContact.allAccount'
import createContact from '@salesforce/apex/CreateContact.createContact'
export default class Createcontact extends LightningElement {
account = '';
firstName = '';
lastName = ''
options = []
constructor() {
super();
this.getAccountInfo();
}
getAccountInfo() {
getallAccount().then(item => {
this.options = item.map(items => {
return {
label: items.Name,
value: items.Id
}
})
})
}
handleChange(event) {
this.account = event.detail.value;
}
firstNames(event) {
this.firstName = event.detail.value;
console.log(this.firstName);
}
lastNames(event) {
this.lastName = event.detail.value;
console.log(this.lastName);
}
createContact() {
console.log(this.lastName, this.firstName, this.account);
createContact({ "Fname": this.firstName, "Lname": this.lastName, "accountId": this.account }).then(item => {
console.log("value insrted");
})
}
}
--------------------------------------------------- Apex Controller -----------------------------------------------------------------------
public without sharing class CreateContact {
@AuraEnabled(cacheable=false)
public static list<Account> allAccount(){
list<account> accountList =[SELECT Id,Name from Account];
system.debug('accountList:::'+accountList);
return accountList;
}
@AuraEnabled(cacheable=false)
public static void createContact(string Fname, string Lname, string accountId){
try{
system.debug('Fname'+Fname);
system.debug('Lname'+Lname);
system.debug('Fname'+Fname);
if(Fname != null && Lname != null && accountId != null){
contact cont = new contact();
cont.LastName =Lname;
cont.AccountId = accountId;
cont.FirstName =Fname;
insert cont;
}
}catch(Exception ex){
system.debug('Exception::'+ex.getMessage()+'at'+ex.getLineNumber());
}
}
}
if it is helpful for you please mark it as the best answer
thank you