Skip to main content

We can't find code that sets the 'annualRevenue' property to the 'value' of the lightning-input's change event. In the accountFinder JavaScript, make sure the event handler reads the 'value' from the change event.

 

// accountFinder.js

import { LightningElement, track } from 'lwc';

export default class AccountFinder extends LightningElement {

    annualRevenue = null;

    handleChange(event) {

        this.annualRevenue = event.target.value;

    }

    reset() {

        this.annualRevenue = null;

    }

}

working fine still not able to finish the challenge

 

3 个回答
  1. 5月9日 11:12

    Hi everyone,

    I wanted to share a solution for a common issue I encountered during the AccountFinder LWC challenge. If you are getting the following error even though your code looks correct, this might help:

    The Issue

    The challenge specifically looks for two things:

    1. The use of event.target.value (instead of event.detail.value) to capture the input.
    2. An active Apex Controller to handle the @wire service.

    The Solution

    The error is often cleared once you correctly implement the Apex Controller and ensure the JS handler is using the expected syntax.

    1. Create the Apex Controller:

    Make sure you have the AccountListControllerLwc class deployed in your org: 

     

    public with sharing class AccountListControllerLwc {

        

        @AuraEnabled(cacheable=true)

        public static List<Account> queryAccountsByRevenue(Decimal annualRevenue) {

            return [

                SELECT Name, AnnualRevenue 

                FROM Account 

                WHERE AnnualRevenue >= :annualRevenue

                WITH SECURITY_ENFORCED

                ORDER BY Name

            ];

        }

     

    2. Update the JavaScript (accountFinder.js):

    Ensure your handleChange method reads the value from event.target.value: 

     

    import { LightningElement, wire } from 'lwc';

    import queryAccountsByRevenue from '@salesforce/apex/AccountListControllerLwc.queryAccountsByRevenue';

    export default class AccountFinder extends LightningElement {

        annualRevenue = null; 

        @wire(queryAccountsByRevenue, { annualRevenue: '$annualRevenue' })

        accounts;

        handleChange(event) {

            this.annualRevenue = event.detail.value;

        }

        reset() {

            this.annualRevenue = null;

        }

     

    Note: Always remember to Deploy the Apex Class first, then deploy your LWC components. After doing a Hard Refresh on your browser, the challenge should pass successfully!

    Hope this helps someone facing the same challenge!

0/9000