0
    import { LightningElement, api, wire } from 'lwc';
    import { getRecord } from 'lightning/uiRecordApi';
    import { NavigationMixin } from 'lightning/navigation';
    
    const FIELDS = ['Payment__c.Company__c']; 

    export default class PrintCheck extends NavigationMixin (LightningElement){
    @api recordId;  

    @wire(getRecord, { recordId: '$recordId', fields: FIELDS })
        payment;
    
        handleClick(event) {
            var company = this.payment.data.fields.Company__c.value;
            console.log('Need name Here Instead of ID'+ company);
        }
    }

It returns id in console.log, but i need name of the lookup field....

2 Answers 2

2

try to use Name in your fields definition

     const FIELDS = ['Payment__c.Company__r.Name']; 
     
      handleClick(event) {
            const company = this.payment.data.fields.Company__r.value.fields.Name.value;            
            console.log('Need name Here Instead of ID'+ company);
        }
3
  • Thanks It worked Klecool :) Commented Jul 9, 2020 at 11:52
  • You're welcome!
    – Klecool
    Commented Jul 9, 2020 at 12:01
  • You can also use import statements and getFieldDisplayValue.
    – sfdcfox
    Commented Jul 9, 2020 at 14:58
2

This is a use case for getFieldDisplayValue:

import { getFieldDisplayValue } from 'lightning/uiRecordApi';
import COMPANYNAMEFIELD from '@salesforce/schema/Payment__c.Company__c';

...

const FIELDS = [COMPANYNAMEFIELD]; 

...

var company = getFieldDisplayValue(this.payment.data, COMPANYNAMEFIELD);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .