function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rick CulbrethRick Culbreth 

parameter variable not recognized on select statement when working Trailhead for Map .NET Concepts to Force.com

I'm admin begging to work on some development.  I'm going through the trailhead module for map .net concepts to force.com.  The exersize was totally different concept than that was covered in the module.  Anyway I'm supposed to build class that has a method that accepts state abreviation and returns a list of accounts that BillingState matches that state.  For some reason I get an invalid token when I use the parameter variable or if I assign the parameter variable value to another string variable in the method.  I can hard code a state and it will compile. Not  sure what I'm missing.  

public with sharing class AccountUtils {
// Public method
    public static List <Account> accountsByState(String Stateab) {
        // Return a list of accounts by state
        String st = Stateab;       
      return [SELECT Id, Name
             FROM Account where (BillingState = Stateab)];     
           }
             } 
Problems show
AccountUtils  Line 7   Unexpect token 'Stateab'
AccountUtils   Line 6   expecting a colon, found 'Stateab'          
Best Answer chosen by Rick Culbreth
Steven NsubugaSteven Nsubuga
public with sharing class AccountUtils {
// Public method
    public static List <Account> accountsByState(String Stateab) {
        // Return a list of accounts by state
        String st = Stateab;       
      return [SELECT Id, Name
             FROM Account where BillingState =: Stateab];     
           }
             }
A full colon before the variable is required.
 

All Answers

Steven NsubugaSteven Nsubuga
public with sharing class AccountUtils {
// Public method
    public static List <Account> accountsByState(String Stateab) {
        // Return a list of accounts by state
        String st = Stateab;       
      return [SELECT Id, Name
             FROM Account where BillingState =: Stateab];     
           }
             }
A full colon before the variable is required.
 
This was selected as the best answer
Rick CulbrethRick Culbreth
Thanks so much Steven.  Did not know that, that worked.  
Steven NsubugaSteven Nsubuga
My pleasure Rick. 
Please do choose a best answer so as to close this question.