2

I have a combo-box in LWC - whose values get populated on load of the page with the help of @wire. The code is as follows:

@wire(fetchL1ProductValues,{userType:'$userType',accountId:'$recordId'})
productList;

get productOptions(){
    console.log('>>>>'+JSON.stringify(this.productList.data));
    return this.productList.data;
}
                    <lightning-combobox
                        class="l1ProductCmp"
                        value={l1SelectedValue}
                        placeholder="-Select-"
                        options={productOptions}
                        onchange={onSelectProductL1} >
                    </lightning-combobox>

   onSelectProductL1(event){
   this.l1product = event.target.value;
    fetchL2ProductValues({productId: this.l1product ,userType: 
           this.userType})
    .then(result => {
      //how to transform the result so that i can populate another combo-box with this result
  }

The issue I'm facing here is that I am not able to populate the second combo-box with the result which i have obtained in onSelectProductL1 function. Imperative method of calling apex is not working in this scenario. we cannot use @wire inside a function. What would be the ideal solution to this problem?

3
  • is fetchL2ProductValues a custom apex method? Do you want to execute and get the result on change of the combo box? Commented Jun 13, 2019 at 18:19
  • Yes it is a custom apex method..which i want to execute & get the result.
    – Sunil
    Commented Jun 14, 2019 at 6:43
  • This link has the solution to this problem. salesforce.stackexchange.com/questions/268353/…
    – Sunil
    Commented Jul 6, 2019 at 18:03

1 Answer 1

1

I think you might want to make use of a second @wire function similar to this using dynamic/reactive variables.

@wire(fetchL1ProductValues,{userType:'$userType',accountId:'$recordId'})
productList;

@wire(fetchL2ProductValues, {userType: '$userType', productId: '$l1productId'})
secondProductList;

@track l1productId;

onSelectProductL1(event) {
  this.l1productId = event.target.value;
}

When l1ProductId changes, the fetchL2ProductValues method should run and update secondProductList. See "Wire an Apex Method with a Dynamic Parameter" here

2
  • On change of l1ProductId , fetchL2ProductValues is not firing again to get the updated values. Do u have a working example for this??
    – Sunil
    Commented Jul 5, 2019 at 8:45
  • This link has the solution to this issue. salesforce.stackexchange.com/questions/268353/…
    – Sunil
    Commented Jul 6, 2019 at 18:04

You must log in to answer this question.

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