function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MOHAMMED BABAMOHAMMED BABA 

Pick list values are not fetching in the lightning data table of lwc component

Hi Team,
i have lwc data table for the custom object Centre_Res__c now i want to show the pick list values for the field which i created Likelihood_Name_Central__c 
import { LightningElement,track,api,wire } from 'lwc';
import { getObjectInfo } from "lightning/uiObjectInfoApi";
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import Centre_Object from '@salesforce/schema/Centre_Res__c';

const columns = [
{
        label: 'Likelihood Ranges Name',
        fieldName: 'Likelihood_Name_Central__c', // Update this fieldName based on your data structure
        editable: true,
        hideDefaultActions: true,
        type: 'combobox', // Specify that this column contains a combobox
        typeAttributes: {
            placeholder: 'Select Likelihood',
            options: '$likelihoodPicklistValues', // Bind to your picklist values
            value: 'selectedLikelihood' // Bind to the selected value
        }
    },
];  after export  
 @api recordId;
    @track likelihoodPicklistValues = [];
    @track recordTypeId;   



@wire(getObjectInfo, { objectApiName: Centre_Object })
   likelihoodObjectMetadata({ error, data }) {
       if (data) {console.log('data'+JSON.stringify(data));
           this.recordTypeId = data; // Set the recordTypeId here based on your use case
           console.log(' this.recordTypeId-->'+JSON.stringify( this.recordTypeId));
       }
   }
   // Fetch picklist values with the specific recordTypeId
   @wire(getPicklistValues, {
       recordTypeId: '$recordTypeId', // Use the custom attribute for recordTypeId
       fieldApiName: 'Centre_Res__c.Likelihood_Name_Central__c'
   })
   wiredPicklistValues({ error, data }) {
       if (data) {
           this.likelihoodPicklistValues = data.values;
           console.log('Picklist Values: ' + JSON.stringify(this.likelihoodPicklistValues));
       } else if (error) {
           console.error('Error fetching picklist values: ' + JSON.stringify(error));
       }
   }
HTML: 
 <template if:true={dataTableValue}>
        <div  class="myTable">
            <lightning-combobox
            label="Likelihood Ranges Name"
            value={selectedLikelihood}
            options={likelihoodPicklistValues}
            onchange={handleLikelihoodChange}
        ></lightning-combobox>
        <lightning-datatable data={dataTableValue} columns={columns} key-field="Id" hide-checkbox-column
        aria-selected="true" onsave={handleSaveDataTable} draft-values={saveDraftValue}
        onrowaction={handleRowAction}>
       
    </lightning-datatable>   can you please help with the exact code or if you have any document where i can see the picklist for custom object 
HarshHarsh (Salesforce Developers) 
Hi Mohammed,
Please try the below js code
import { LightningElement, track, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import Centre_Object from '@salesforce/schema/Centre_Res__c';

const columns = [
  {
    label: 'Likelihood Ranges Name',
    fieldName: 'Likelihood_Name_Central__c',
    editable: true,
    hideDefaultActions: true,
    type: 'combobox',
    typeAttributes: {
      placeholder: 'Select Likelihood',
      options: '$likelihoodPicklistValues',
      value: 'selectedLikelihood'
    }
  },
];

export default class YourComponent extends LightningElement {
  @track likelihoodPicklistValues = [];
  @track selectedLikelihood = '';
  @track saveDraftValue = [];
  @track dataTableValue = []; // You should populate this with your data

  @wire(getObjectInfo, { objectApiName: Centre_Object })
  likelihoodObjectMetadata({ error, data }) {
    if (data) {
      this.recordTypeId = data.defaultRecordTypeId;
    }
  }

  @wire(getPicklistValues, {
    recordTypeId: '$recordTypeId',
    fieldApiName: 'Centre_Res__c.Likelihood_Name_Central__c'
  })
  wiredPicklistValues({ error, data }) {
    if (data) {
      this.likelihoodPicklistValues = data.values.map(picklistValue => ({
        label: picklistValue.label,
        value: picklistValue.value
      }));
    } else if (error) {
      console.error('Error fetching picklist values: ' + JSON.stringify(error));
    }
  }

  handleLikelihoodChange(event) {
    this.selectedLikelihood = event.detail.value;
  }

  handleSaveDataTable(event) {
    // Handle saving data in the datatable here
  }

  handleRowAction(event) {
    // Handle row actions here
  }
}
  • Please check that the data you want to display in the lightning-data table is properly defined in your dataTableValue.
  • make sure to map the picklist values to have both a label and a value property for the combo box options.
  • If you are still facing issues, please provide more details about the problem you are encountering or any error messages, and I'll be happy to assist further.

Please mark it as Best Answer if the above information was helpful.

Thanks.

Heads up about the Forums shut down

User-added image
Important Update

We appreciate your participation in these Salesforce Discussion Forums! It’s active members like you that keep our amazing community going strong.

At this time, we want to give you a heads up that on December 4, 2023, the discussion forums will shut down and all relevant discussions will migrate to the Trailblazer Community digital platform. This move brings all conversations around Salesforce development together in one place and provides more opportunities for our broader community to connect and share. We will be removing outdated, obsolete, or spam content and migrating only relevant discussions to the Trailblazer Community digital platform.

Starting November 20, you can view discussions but not post new questions or responses. On December 2, you will no longer be able to access the discussion forums from the Salesforce Developers website.

Please take these steps before November 30, 2023, 11:59 p.m. PT to ensure your contributions follow you to the Trailblazer Community:
  1. If you’re not already a member of the Trailblazer Communitysign up for a Trailblazer account using the same login email address associated with your Developer Discussion Forums account. This is crucial.
  2. If you already have a Trailblazer account, and it’s using a different email address from the one you used for your Developer Discussion Forums account, we recommend that you log in to the Trailblazer Community and connect your forums email address to your Trailblazer account.
Once you’re in the Trailblazer Community, join the Migration Support Hub users group to help you navigate this transition.

We will keep you up to date throughout the transition, and we look forward to seeing you joining the developer discussions in the Trailblazer Community!

Sincerely,
The Forums Support Team