Gets a field’s value from a record. Spanning fields are supported.
The field’s value is returned in its raw data form. In some cases, the raw data form differs from the display value that’s returned by getFieldDisplayValue(record, field).
A Record object from which to retrieve the field value.
field
String
The API name of the field. The value can be either a string or reference to a field imported from @salesforce/schema. You can specify up to three relationship fields to reference parent objects and fields using this format: <SObjectName>.<relationship-1>.<relationship-2>.<relationship-3>.<fieldName>.
Returns
The field’s value. A record may be returned if a relationship field is used. If the field you are requesting for doesn’t exist, this function returns undefined.
Usage
To get the value of a record’s field, you can use the getRecord wire adapter, which returns the property record.data.fields.fieldName.value. However, you can also call getFieldValue(record, field) to get the value directly.
The field value is returned in its raw data form, which is useful for calculations and comparisons. Here are a few examples of values in raw data form:
Currency values are displayed like 350000000.
Date values are displayed like 2019-07-13
Date/time values are displayed like 2015-06-17T22:17:58.000Z.
Import the field references that you pass to getFieldValue(record, field) from the @salesforce/schema scoped package using the @salesforce/schema/ObjectName.FieldName syntax. For a custom object, use the @salesforce/schema/CustomObjectName__c.CustomFieldName__c syntax. If you use a string to identify a field name like fields: ["Account.Name"], you don’t get the benefits that you get from importing a reference to the field. See Import References to Salesforce Objects and Fields.
1import{LightningElement, api, wire}from "lwc";2import{getRecord, getFieldValue}from "lightning/uiRecordApi";34import REVENUE_FIELD from "@salesforce/schema/Account.AnnualRevenue";5import CREATED_FIELD from "@salesforce/schema/Account.CreatedDate";6import EXP_FIELD from "@salesforce/schema/Account.SLAExpirationDate__c";78const FIELDS = [REVENUE_FIELD, CREATED_FIELD, EXP_FIELD];910export default class WireGetValue extends LightningElement{11 @api recordId;1213 @wire(getRecord, {recordId: "$recordId", fields: FIELDS})14 account;1516 get revenue(){17 return getFieldValue(this.account.data, REVENUE_FIELD);18}1920 get created(){21 return getFieldValue(this.account.data, CREATED_FIELD);22}2324 get expiration(){25 return getFieldValue(this.account.data, EXP_FIELD);26}27}