+ Start a Discussion
Gregory512Gregory512 

Defining filter criteria for a lit in a custom controller

Hi,

I'm trying to extend the filter criteria in this code to show only records whose date field (workshop_date__c) are either today or in the future.

Any ideas on how I edit this code to do that?

listClass = [Select Id, Name, Contact__c,Contact__r.Name, Product2__c,Product2__r.Name, Workshop_Date__c From SFDC_Class__c Where Product2__r.Name = 'Austin CEU Workshop' Limit 1000];

 


Just to be clear.. this is the code from a custom controller used for a visualforce page displayed publicly with sites.  

Thanks for helping out a newb.

Best Answer chosen by Admin (Salesforce Developers) 
Greg HGreg H

You forgot to add the 'AND' statement to your clause. Also, you don't need to include the field name in quotes. Your code should look like this:

listClass = [SELECT Id, Name, Contact__c, Contact__r.Name, Product2__c, Product2__r.Name, Workshop_Date__c, Start_Time__c, End_Time__c, CEU_Hours__c, Workshop_Price__c FROM SFDC_Class__c WHERE Product2__r.Name = 'Austin CEU Workshop' AND Workshop_Date__c >= TODAY Limit 1000];

The TODAY variable will be dynamically populated by Salesforce with the correctly formatted value for the current date so it should not be enclosed in quotes either.
-greg

All Answers

Greg HGreg H

In your WHERE clause add the filter "Workshop_Date__c >= TODAY".
-greg

Gregory512Gregory512

Thanks Greg,

 

It doesn't seem to like me just adding that.  Here's what I tried:

 

listClass = [Select Id, Name, Contact__c,Contact__r.Name, Product2__c,Product2__r.Name, Workshop_Date__c, Start_Time__c, End_Time__c, CEU_Hours__c, Workshop_Price__c From SFDC_Class__c Where Product2__r.Name = 'Austin CEU Workshop' 'Workshop_Date__c' >= TODAY Limit 1000]; }

is there something that goes between the two criteria?  how should this be structured?

 

Thanks for your help.

Greg HGreg H

You forgot to add the 'AND' statement to your clause. Also, you don't need to include the field name in quotes. Your code should look like this:

listClass = [SELECT Id, Name, Contact__c, Contact__r.Name, Product2__c, Product2__r.Name, Workshop_Date__c, Start_Time__c, End_Time__c, CEU_Hours__c, Workshop_Price__c FROM SFDC_Class__c WHERE Product2__r.Name = 'Austin CEU Workshop' AND Workshop_Date__c >= TODAY Limit 1000];

The TODAY variable will be dynamically populated by Salesforce with the correctly formatted value for the current date so it should not be enclosed in quotes either.
-greg

This was selected as the best answer