LWC開発JSでオブジェクトのレコードタイプの取得

 

LWC開発JSでオブジェクトのレコードタイプの取得

 

 

HTMLファイル:

 

<lightning-record-edit-form record-type-id={RecTypeId} object-api-name="Opp__c">
<!--<lightning-record-edit-form object-api-name="Opp__c">//一般的なオブジェクト依存の選択リスト項目-->
    <lightning-input-field 
                    data-name="StageName" 
                    data-id="StageName"
                    field-name="StageName__c"
                    required >
    </lightning-input-field>
</lightning-record-edit-form>

 

JSファイル

import { api,LightningElement, wire, track } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import CUS_OBJECT from '@salesforce/schema/Opp__c';//オブジェクトのAPI名はここに設定
 
recordTypeValue = '欲しいレコードタイプ';
  @track RecTypeId;

  @wire(getObjectInfo, { objectApiName: CUS_OBJECT })
 
handleObjectInfo({error, data}) {
        if (data) {
            const rtis = data.recordTypeInfos;
            this.RecTypeId= Object.keys(rtis).find(rti => rtis[rti].name === 'レコードタイプAPI名');
           
        }
    }