Hey guys, today in this post we are going to learn about How to get custom lookup field value and assign to other lookup fields value in LWC.
Create relationships to link objects with each other, so that when your users view records, they can also see related data.
Lookup Links two objects together. Lookup relationships are similar to master-detail relationships, except they donβt support sharing or roll-up summary fields. To more details about Lookup relationships, Click Here.
Final Output β
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
- Find the below steps βΎ
Create Lightning Web Component HTML
Step 1:- Create Lightning Web Component : lookupFieldValueLwc.html
SFDX:Lightning Web Component >> New >> lookupFieldValueLwc.html
As per student's demands, I re-opened my eBook of "Salesforce Tutorial" Limited-time huge discount offer Absolutely 50% Off.
I am thinking to give you discount offer occasion of Gandhi Jayanti for a powerful "Salesforce admin course" where you can Understand from Basic Concepts to advanced label in Salesforce.
π So Don't MISS it... (Access Right Now)
π Get Huge Discount Offer 50%: - Get eBook
lookupFieldValueLwc.html [Lightning Web Component HTML]
<template>
<lightning-card title="Lookup Field Value" style="font: size 18px; ">
<div class="slds slds-grid slds-wrap slds-p-around_medium">
<div class="slds-col slds-size_6-of-12">
<div class="slds-form-element">
<div class="slds-form-element_controller">
<lightning-record-edit-form object-api-name="Contact">
<lightning-input-field field-name="AccountId" data-type="input-field" value={accountId} name="accountId" onchange={handleChangeAction}>
</lightning-input-field>
</lightning-record-edit-form>
</div>
</div>
</div>
<div class="slds-col slds-size_6-of-12">
<div class="slds-form-element">
<div class="slds-form-element_controller">
<lightning-record-edit-form object-api-name="Contact">
<lightning-input-field field-name="ReportsToId" data-type="input-field" value={reportsToId} name="reportsToId" onchange={handleChangeAction}>
</lightning-input-field>
</lightning-record-edit-form>
</div>
</div>
</div>
</div>
</lightning-card>
</template>
Create Lightning Web Component JavaScript
Step 2:- Create Lightning Web Component : lookupFieldValueLwc.js
SFDX:Lightning Web Component >> New >> lookupFieldValueLwc.js
lookupFieldValueLwc.js [LWC JavaScript File]
import { LightningElement,track, api } from 'lwc';
export default class LookupFieldValueLwc extends LightningElement {
@track accountId ;
@track reportsToId;
handleChangeAction(event){
if(event.target.name == 'accountId'){
this.accountId = event.target.value;
//window.console.log('accountId ##' + this.accountId);
if(this.accountId == '0015g00000y2ZQEAA2')
{
this.reportsToId = '0035g00000FroJAAAZ';
}else{
this.reportsToId = '';
}
}
if(event.target.name == 'reportsToId'){
this.reportsToId = event.target.value;
window.console.log('reportsToId ##' + this.reportsToId);
}
}
}
Create Lightning Web Component Meta XML
Step 3:- Create Lightning Web Component : lookupFieldValueLwc.js-meta.xml
SFDX:Lightning Web Component >> New >> lookupFieldValueLwc.js-meta.xml
lookupFieldValueLwc.js-meta.xml [LWC Meta Data XML]
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>56.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Further post that would you like to learn in Salesforce
What is the use of @track in LWC?
The @track decorator is used to track changes to a property in a LWC component. This allows the component to automatically rerender itself whenever the value of the decorated property changes.
How do I fetch picklist values in LWC?
Import getPicklistValues wire method in your js file to get picklist values. Import getObjectInfo wire method in your js file to get default record type id. Call getObjectInfo wire to get default recordtype id. Now call getPicklistValues to get picklist values.
What is lookup formula value?
Lookup_value can be a value or a reference to a cell. The range of cells in which the VLOOKUP will search for the lookup_value and the return value. You can use a named range or a table, and you can use names in the argument instead of cell references. The first column in the cell range must contain the lookup_value.
Related Topics | You May Also Like
- My Udemy Course β



