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:


get productOptions(){
    return this.productList.data;
                        onchange={onSelectProductL1} >

   this.l1product = event.target.value;
    fetchL2ProductValues({productId: this.l1product ,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?

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

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


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

@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.