1
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

6

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];
}
3
  • it should be public static List<Account> accountsByState(String stateAbbr) { return [SELECT Id, Name FROM Account WHERE BillingState=:stateAbbr]; } Anyway, thank you a ot!1
    – Ryan Ren
    Sep 20 '19 at 3:21
  • There is no prob with extra field. Trailhead will accept it Sep 20 '19 at 3:27
  • Can you close the question if it solved. Pls go through meta.stackexchange.com/questions/5234/… Sep 21 '19 at 7:29

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.