Friday, January 12, 2024

Lightning Record Picker in Salesforce

The lightning-record-picker component allows you to search for a list of Salesforce Records that match search input. It uses the GraphQL wire adapter to search for records, displays the records, and allows the user to select a record.

 Ex:

HTML

<template>
	<lightning-card title="Lightning Record Picker" icon-name="standard:account">
	<lightning-record-picker label="Select Account" 
							 onchange={handleRecordChange} 
							 placeholder="Search Accounts..." 
							 object-api-name="Account"
							 display-info={displayInfo}>
		</lightning-record-picker>
		<template lwc:if={selectedRecordId}>Selected Record Id: {selectedRecordId}</template>
	</lightning-card>
</template>
JS

import { LightningElement } from 'lwc';

export default class RecordPicker extends LightningElement {
    selectedRecordId;

    displayInfo = {
        additionalFields: ['Phone', 'Industry']
    }
    handleRecordChange(event) {
        this.selectedRecordId = event.detail.recordId;
    }
}



No comments:

Post a Comment