๐ก @Wire
using wire adapters you can import references to salesforce objects and fields
1. Import a reference to an object
import POSITION_OBJECT from '@salesforce/schema/Position__c';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
2. Import reference to a field
import POSITION_LEVEL_FIELD from '@salesforce/schema/Position__c.Level__c';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name';
3. Import reference to relationship field
import POSITION_HIRINGMANAGER_NAME_FIELD__C from '@salesforce/schema/Position__C.HiringManager__r.Name';
import ACCOUNT_OWNER_NAME_FIELD from '@salesforce/schema/Account.Owner.Name';
4. Import field and use it in a wire adapter config object
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.name';
export default class Record extends LightningEelement{
@api recordId;
@wire (getRecord, {recordId: '$recordId', fields:[ACCOUNT_NAME_FIELD]})
record;
}
๐ต wireWithProperty.html
<<template>
<p>
<b>Account Name : {name}</b>
</p>
</template>
๐ต wireWithProperty.js
import { LightningElement, wire , api} from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name';
export default class WireWithProperty extends LightningElement {
@api recordId;
@wire(getRecord, {recordId : "$recordId" , fields:[ACCOUNT_NAME_FIELD] })
record;
get name(){
console.log("name:" + this.record.data +"/"+ "recordId : " + this.recordId);
return getFieldValue(this.record.data, ACCOUNT_NAME_FIELD )
}
๐นwireWithFunction.js
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
export default class WireWithFunction extends LightningElement {
@api recordId;
accounts;
error;
@wire (getRecord, {recordId:'$recordId', fields:['Account.Name']})
WireAccount({error, data}) {
console.log('@@@Getting data from wore with function');
this.accounts = data;
}
elseif (error){
this.error = error;
console.log('###Error : ' + error.body.message);
}
}
์๋ดค์ต๋๋ค