getFieldValue(record, field)

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).

  • record—(Required) A Record object from which to retrieve the field value.
  • field—(Required) 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 5 levels of spanning fields. For example, Opportunity.Account.CreatedBy.LastModifiedById returns 4 levels of spanning fields.

The field’s value. A record may be returned if a spanning field is used. If the field you are requesting for doesn’t exist, this function returns undefined.

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.

To display formatted values, use base components such as lightning-formatted-number or lightning-formatted-date-time. The locale set in the Salesforce user preferences determines the formatting.

The base components display the values:

  • $350,000,000.00
  • Wednesday, Jun 17, 2015, 03:17 PM
  • Jul 13, 2014

Alternatively, use the getFieldDisplayValue(record, field) wire adapter to display the formatted and localized value for a field.