0

I used this formula but it keeps displaying Contact everytime

Data Type Formula
IF(RecordTypeId = "0123z000000KmJvAAK", "Contact", IF(RecordTypeId = "0123z000000KmK5AAK", "Condidat", NULL))

   <lightning-output-field
        field-name="Record_Typess__c" 
    ></lightning-output-field>
2
  • You cannot use formula directly in the HTML markup of LWC. create a JS property. May 7, 2020 at 15:13
  • I used it setup and not ob html i just call it with lightning output field
    – Oumaima
    May 7, 2020 at 15:16

3 Answers 3

3

You can use the recordTypeInfo.name follow this code

import { LightningElement, api, track, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';

export default class WireFunction extends LightningElement {
  @api recordId;
  @track record;
  @track error;

  @wire(getRecord, { recordId: '$recordId', fields: ['Account.Name'] })
  wiredAccount({ error, data }) {
      if (data) {
          this.record = data;
console.log('data.recordTypeInfo ',data.recordTypeInfo.name);
          this.error = undefined;
      } else if (error) {
          this.error = error;
          this.record = undefined;
      }
  }
2

This should help

  import { LightningElement, api, wire, track } from 'lwc';
    import { getObjectInfo } from 'lightning/uiObjectInfoApi';
    import ACCOUNT_OBJECT from '@salesforce/schema/Account';
    import RECORDTYPEID from '@salesforce/schema/Account.RecordTypeId';
    const _FIELDS = [RECORDTYPEID];
    export default class RecordFormWithRecordType extends LightningElement {
        // Flexipage provides recordId and objectApiName
        @api recordId;
        @api objectApiName;

        @track objectInfo;

        @wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
        objectInfo;

        @wire(getRecord, { recordId: '$recordId', fields: _FIELDS })
        account;

        get recordTypeName() {
            // Returns a map of record type Ids 
            const rtis = this.objectInfo.data.recordTypeInfos;
            const rtId = getFieldValue(this.account.data, RECORDTYPEID));
            const rtInfo = Object.keys(rtis).find(rti => rtis[rti].id === rtId);
            return rtInfo.name;
        }
    }
11
0

it works perfect.

ref :https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.reference_wire_adapters_object_info

getRecordTypeNameById(rtId) {
    // Returns a map of record type Ids 
    const rtis = this.objectInfo.data.recordTypeInfos;
    if(rtis[rtId]){
        // If found, Returns Name of record type Id
        return rtis[rtId].name;
    } else {
        // If NOT found, Return Null
        return null;
    }
}

You must log in to answer this question.

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