useSObject
Import
import { mix, useSObject, BoltElement } from 'c/boltage';
Usage
export default class myLwc extends mix( BoltElement, useSObject({ fields, recordTypeId, objectApiName })) { }
Methods
Constructor({fields,recordTypeId?,objectApiName?}) : Constructor
Name | Type | Description |
---|---|---|
fields | Field[] | (this) => Field[] | List of imported fields |
recordTypeId ? | RecordId | Defaulted to default |
objectApiName ? | String | Only needed if the param fields matches this type (this) => Field[] |
Example
import FirstName from '@salesforce/schema/Contact.FirstName';export default class myLwc extends mix( BoltElement, useSObject({ fields: [FirstName] })) {}
Dynamic fields
import FirstName from '@salesforce/schema/Contact.FirstName';import LastName from '@salesforce/schema/Contact.LastName';export default class myLwc extends mix( BoltElement, useSObject({ fields: (self) => self.chosenFields, objectApiName: 'Contact' })) { chosenKey; get chosenFields() { return this.chosenKey === 'firstname' ? [FirstName] : [LastName]; }}
Dynamic Attributes
<relatedListApiName>__ref : RecordRef
The __ref
identifier gives a boilerplate object whose keys represent the imported fields and where values are initialized as null.
Contact__ref: { FirstName: null}
Example
import FirstName from '@salesforce/schema/Contact.FirstName';export default class myLwc extends mix( BoltElement, useSObject({ fields: [FirstName] })) {}
<template> <lightning-input value={Contact__ref.FirstName}> </lightning-input></template>
<relatedListApiName>__info : RecordInfo
The __info
identifier gives a description of the object including :
- label
- dataType
- picklistValues (if is of type picklist)
Contact__info: { FirstName: { label: "Contact's First Name", dataType: "string", }}
Example
import FirstName from '@salesforce/schema/Contact.FirstName';export default class myLwc extends mix( BoltElement, useSObject({ fields: [FirstName] })) {}
<template> <lightning-input label={Contact__info.FirstName.label}> </lightning-input></template>