0

I am trying to create a custom list view and deploy a LWC that lists records in the list. My component works with dummy data, but once I created an Apex class to execute my SOQL query it is having issues.

I know my Apex class works fine since I tried it without filtering functionality.

However, to add filtering functionality I am also using @track. So that I can track the value of the current items to display based on which filter is active.

I am suspecting that my usages of @wire and @track are problematic.

When I call @track on my dummy, local list inside the JS file, there is no issue (no use of @wire at all). When I try to track applications that is a result of the @wire, the component refuses to load. How can I fix this?

1 Answer 1

2
@track itemsForCurrentView = applications; 

The value will only be assigned once, so it won't be reactive.

@wire(getLoanApplications) applications;

You need to pass in the filter properties, if any, and make them reactive:

@wire(getLoanApplications, { filter: '$currentFilter' }) 
applications;

If you need to do any post-processing, do it with a handler:

@wire(getLoanApplications, { filter: '$currentFilter' }) 
applicationsWireHandler({data,error}) {
  if(data) {
    // You can massage the data if you need to //
    this.itemsForCurrentView = data;
  }
  if(error) {
    // display an error // 
  }
}
10
  • When you say "pass in filter properties, and make them reactive" would I do @track itemsForCurrentView = applications? Or does your code snippet already make it reactive? When I try assigning applications to the @wire with the filter, I get an error saying applications is not defined.
    – Lia
    Jun 20, 2021 at 22:56
  • @Lia No, you do not do the assignment; that's only for assigning a default value. @wire variables automatically cause update renders, so you do not need to @track them manually or assign them elsewhere.
    – sfdcfox
    Jun 21, 2021 at 2:18
  • Then how do I initialize itemsForCurrentView?
    – Lia
    Jun 21, 2021 at 11:54
  • Is there elsewhere where I need to initialize applications? I keep getting an error saying it is not defined.
    – Lia
    Jun 21, 2021 at 11:59
  • So it looks like whenever I try to set itemsForCurrentView to applications it thinks applications is not defined. How else can I set default itemsForCurrentView as the applications?
    – Lia
    Jun 21, 2021 at 12:44

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.