2

I have a LWC where I am populating the picklist using wire service.

@wire(getPicklistValues , {recordTypeId: '$accountItem.data.defaultRecordTypeId',fieldApiName: ACCT_ITEM_STATUS })
acctStatus; 

Wire populates picklist

  <template if:true={acctStatus.data}>
        <lightning-layout-item size="3" padding="around-small">
            <lightning-combobox value={value} placeholder="Complete" onchange = {handleAcctChange} options={acctStatus.data.values} label="Account Item Status" ></lightning-combobox>
        </lightning-layout-item>
    </template>

2 Questions
1.How can I pass the the placeholder value to a connectedcallback?
2.How do I pass the picklist onchange value to the connectedcallback?

import getAcctLayout from '@salesforce/apex/AccountController.getAccountItems';

async connectedCallback() {

const acctLayout = await getAcctLayout({acctId: this.recordId, acctStatus: picklist value})
2
  • 1. i belive placeholder value complete is static ? why again you need to get from component 2. why you need to pass picklist value connectedcallback event? for getAcctLayout function? what are you doing in getAcctLayout function? is any Apex server call?
    – sdandamud1
    Feb 23, 2022 at 17:28
  • 1. Yes, 'complete' is a value in the picklist list. I was trying to set it as a default. I am trying to pass the picklist value to determine which records that will be selected in the Apex class that will determine what records to render.
    – Phuc
    Feb 23, 2022 at 17:34

1 Answer 1

4

you have to use reactive wire mechanism using $, added sample code

import {LightningElement, wire} from 'lwc';
import getAcctLayout from '@salesforce/apex/AccountController.getAccountItems';


   selectedPLValue = '';
   async connectedCallback() {
      this.selectedPLValue  = 'Complete'; // call wire service first time loads after set the value complete
   }
   @wire(getAcctLayout({acctId: this.recordId, acctStatus: '$selectedPLValue'}))
   acctLayout;

   handleAcctChange(event) {
       this.selectedPLValue  = event.detail.value; // call wire service when value changes
   }
4
  • So move getAcctLayout out of the connectedcallback? Just want to confirm. Also, will the updating the picklist value case the onchange to fire the connectedcallback? Thanks
    – Phuc
    Feb 23, 2022 at 17:59
  • yes make getAcctLayout as wire service out from connectedcallback and call dynamically with reactive. onchange event of picklist don't fire the connectedcallback ,it fires getAcctLayout wire service after update the selected value
    – sdandamud1
    Feb 23, 2022 at 18:49
  • This worked. Thank you. For others info. I moved the getAcctLayout code outside the connectedCallBack and used async instead or @wire. I also made my changeEvent into async function.
    – Phuc
    Feb 24, 2022 at 15:42
  • still i don't understand the reason for using async & await. is there any specific scenario to use ?
    – sdandamud1
    Feb 24, 2022 at 15:56

You must log in to answer this question.

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