Skip to content

Instantly share code, notes, and snippets.

@banderson5144
Created June 14, 2022 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banderson5144/4d5c883b41673cd38e1fd0da5053108c to your computer and use it in GitHub Desktop.
Save banderson5144/4d5c883b41673cd38e1fd0da5053108c to your computer and use it in GitHub Desktop.
LWC getRecord Usage
import { LightningElement, wire, api } from "lwc";
//1. import the methods getRecord
import { getRecord } from "lightning/uiRecordApi";
//2. Import reference to the object and the fields
import NAME_FIELD from "@salesforce/schema/Account.Name";
import RATING_FIELD from "@salesforce/schema/Account.Rating";
import INDUSTRY_FIELD from "@salesforce/schema/Account.Industry";
const FIELDS = [NAME_FIELD, RATING_FIELD, INDUSTRY_FIELD];
export default class GetRecordTestUpdate extends LightningElement
{
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
wiredRecord({ error, data })
{
console.log('fooey');
if(data && data.fields.Rating.value == 'Cold')
{
console.log('The Rating is Cold');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment