Skip to content

Instantly share code, notes, and snippets.

@arufian
Last active February 25, 2024 22:19
Show Gist options
  • Save arufian/790f5004d33081f6bd207271dab43668 to your computer and use it in GitHub Desktop.
Save arufian/790f5004d33081f6bd207271dab43668 to your computer and use it in GitHub Desktop.
How to use dynamic fields at @wire getRecord - LWC (Lightning Web Component)
import { LightningElement, track, wire, api } from 'lwc';
export default class DynamicFields extends LightningElement {
@api recordId;
@track fields;
@api objectApiName;
@wire(getRecord, { recordId: '$recordId', fields: '$fields' })
record;
connectedCallback() {
this.fields = this.objectApiName === 'Account'? ['Account.BillingCity', 'Account.Name']: ['Contact.MailingCity', 'Contact.Name'];
}
renderedCallback() {
console.log(this.record, 'record');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment