1

I have a picklist in a combo-box, on change of the picklist value @ wire method should fire is it possible or what is the work around??. As per the below example when this.l1productId value changes in the on change event method,@wire(fetchL2ProductValues) should fire.

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

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

    @track l1productId;

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

closed as unclear what you're asking by Pranay Jaiswal, Mohith Shrivastava, Vijay Ganji, Raul, battery.cord Jul 10 at 13:53

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Your code is supposed to work. The l1productId update is already detected by the call of your fetchL2ProductValues method. What isn't working? – Martin Lezer Jul 5 at 8:58
  • I put debug logs to check if my apex code is getting called..but i don't see the debug logs in my method where i return l2 value's based on productl1 – Sunil Jul 5 at 9:07
  • Could it be because of the cache? Do you change with values you never chose before? – Martin Lezer Jul 5 at 9:09
  • Yes i changed the values..put alerts & confirmed that values got changed. But i feel @wire works fine only 'ON LOAD'. – Sunil Jul 5 at 9:24
  • whats the type of the userType variable? I think @wire service only work with primitive data type as parameters. – Martin Lezer Jul 5 at 9:29
3

Try to call refreshApex from the @salesforce/apex which refreshes the cache.

You can find example and documentation here

  • Tried the same..but l1selectedValue is still holding the value it got populated while page load. onSelectProductL1(event){ alert('before change '+this.l1SavedValue ); this.l1SavedValue = event.target.value; alert('after change '+this.l1SavedValue); alert('before refresh apex'); refreshApex(this.l2ProductList); } @wire(fetchL2ProductValues,{productId: '$l1SavedValue',userType: '$userType'}) l2ProductList; – Sunil Jul 5 at 12:07
  • Thanks for the help.I resolved the issue. – Sunil Jul 5 at 18:06
0

I was able to resolve this by using refreshApex.I was setting the value for this.l1SavedValue in JS onload method "renderedCallback". Every time on change event fired, onload event used to get called & it used to reset the value back to onload value. Hence i used the following code in renderedCallback. By using If we prevent onload method to reset the value of this.l1SavedValue for subsequent changes.

 if(this.l1SavedValue === undefined){
        this.l1SavedValue = result.Product_L1__c;
 }

 @wire(fetchL2ProductValues,{productId: '$l1SavedValue',userType: '$userType'}) 
 l2ProductList;

  onSelectProductL1(event){ 
  this.l1SavedValue = event.target.value; 
  refreshApex(this.l2ProductList);
  }

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