0
// Object = Free_Budget__c
// Picklist = Reason__c


import { getPicklistValues, getObjectInfo } from 'lightning/uiObjectInfoApi';
import Reason from '@salesforce/schema/Free_Budget__c.Reason__c';

export default class MultipleAccountInsertion extends LightningElement {

    @track pickListValues;
    @track error;
    @track values;

    @wire(getPicklistValues, {
            recordTypeId: "$getObjectInfo.data.defaultRecordTypeId",
            fieldApiName: Reason
        })
        reasonValues;

        wiredPicklistValue({ data, error}){
            if(data){
                console.log(`Picklist values are ${data}`);
                this.pickListValues = data.values;
                this.error= undefined;
            }
            if(error){
                console.log(`Error while fetching Picklist values ${error}`);
                this.error = error;
                this.pickListValues = undefined;
            }
        }

<template>

            <template for:each={freeBudgetRecList} for:item="Free_Budget__c" for:index="index">
                <tr key={keyIndex}>
                    <td>
                        <div class="slds-m-top_medium">
                            {index}
                        </div>
                    </td>
                    <td>
                        <div class="slds-m-top_large">
                            <lightning-record-edit-form object-api-name="Free_Budget__c" id={index} >
                                <lightning-input-field field-name="Account__c" variant="label-hidden" access-key={index} onchange={changeHandler} value={Free_Budget__c.Account__c} required> </lightning-input-field>
                            </lightning-record-edit-form>
                        </div>
                    </td>
                    <td>
                        <lightning-input name="fbAmount" access-key={index} id={index} type="Currency" onchange={changeHandler} value={Free_Budget__c.Amount__c} required>
                        </lightning-input>
                    </td>
                    <td>
                        <lightning-input name="fbEffectiveDate" access-key={index} id={index} type="Date" onchange={changeHandler} >
                        </lightning-input>
                    </td>
                    <td>
                        <lightning-input name="fbReason" access-key={index} id={index} type="Text" onchange={changeHandler} value={Free_Budget__c.Reason__c}>
                        </lightning-input>
                    </td>  
                    <td>
                        **<lightning-combobox name="level"
                          label="Level"
                          value={value}
                           placeholder="-Select-"
                           options={reasonValues.data.values}
                    >
                        </lightning-combobox>**  
                    </td>           
                    <td>
                        <div class="slds-m-top_medium">
                            <lightning-icon icon-name="action:delete" access-key={index} id={index} alternative-text="Click to Call" size="small" title="large size" onclick={removeRow}>
                            </lightning-icon>
                        </div>
                    </td>
                
                </tr>
                
            </template>
        
        </table>
    </lightning-card>
 </template>

2 Answers 2

1

your template is rendered before the wire could retrieve the picklist values, thus reasonValues.data is undefined and trying to render reasonValues.data.values gives an error. You can prevent this by making sure the combobox doesn't render before the values are available using <template if:true={resonValues.data}>

1

As wire are asynchronous, I think LWC tries to render your template before the wire result is returned.

This means that at first reasonValues may not yet be populated. Try to add a rendering condition in your template to only render your combobox when the wire has returned results:

<template if:true={reasonValues.data}>
    <lightning-combobox name="level"
        label="Level"
        value={value}
        placeholder="-Select-"
        options={reasonValues.data.values}>
    </lightning-combobox>
</template>

You must log in to answer this question.

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