+ Start a Discussion
John NeffJohn Neff 

How do I add a WHERE condition to my controller?

Hello!

I would like to add a condition to my controller so that only records that match a certain field value will be evalueted... but I can not get the syntax correct.  Here is what I currently have: 
 
[Select id, name, Call_Volume_This_Week__c, Spend_Last_Week__c, Week_to_Date_SpendFRM__c, Record_Scope__c from Buyer_Performance__c]

And I would like it to function as: 

[Select id, name, Call_Volume_This_Week__c, Spend_Last_Week__c, Week_to_Date_SpendFRM__c, Record_Scope__c from Buyer_Performance__c WHERE Record_Scope__c = "YES"]

How would I properly execute this?

Thanks, 

John
Best Answer chosen by John Neff
Priya GovindasamyPriya Govindasamy
Hi John,

 Try using single quotes instead of double quotes in WHERE ...
  WHERE Record_Scope__c = 'YES'
 

All Answers

Chad MoutesChad Moutes
What type of field is Record Scope? Checkbox? or Picklist?

What syntax error are you getting?
 
John NeffJohn Neff
Thanks so much for your help Chad! It is a custom formula field that has a text output. When I try this: [Select id, name, Call_Volume_This_Week__c, Spend_Last_Week__c, Week_to_Date_SpendFRM__c, Record_Scope__c from Buyer_Performance__c WHERE Record_Scope__c = "Yes" ]; I get this error: Error: Compile Error: line 9:171 no viable alternative at character '"' at line 9 column 171 What am I doing incorrectly?
Chad MoutesChad Moutes
Try this,

Delete the following - WHERE Record_Scope__c = "YES" then save the file. If it saves then edit it again and re add that line of code but type it out, do not paste it.
 
John NeffJohn Neff
Sure thing, I was able to save the class after deleting the WHERE... portion, but upon retyping it out I am getting the same error. 

I will try and convert the field to a Checkbox and see if I can just use TRUE. 

 
Priya GovindasamyPriya Govindasamy
Hi John,

 Try using single quotes instead of double quotes in WHERE ...
  WHERE Record_Scope__c = 'YES'
 
This was selected as the best answer
John NeffJohn Neff
That did  it!!

Thank you so much Priya!
Priya GovindasamyPriya Govindasamy
Thanks John,

I am glad... I could help !
John NeffJohn Neff
You can definitly tell that I am a newbie!

Thanks again!