[SalesForce] How to Create an Apex class that returns Account objects

public class AccountUtils {
    public static void accountByState(){

            List<Account> myAccounts = [SELECT Id, Name FROM Account];
    }
}

Why my code doesn't complete the challenge of trailhead? What is wrong?

the requirements are:

Create an Apex class named AccountUtils and include a static method
named accountsByState that accepts a state abbreviation as a string
and returns a List of Account objects The method must return the ID
and name of all Account objects that match the BillingState for the
state abbreviation passed to the method

Best Answer

method named accountsByState that accepts a state abbreviation as a string and returns a List of Account objects

You are not passing the parameter for state.

public static List<Account> accountsByState(String stateAbbr) {
    return [SELECT Id, Name, BillingState FROM Account WHERE BillingState=:stateAbbr];
}
Related Topic