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
LeeMurphyLeeMurphy 

Selecting records where a datetime value meets criteria

I'm fairly new to apex and only have experience with c# and VB, so apologies if this is a simpleton question.

 

I have a field called Feedback Email Sent Date (which intuitively is the datetime value a feedback email was sent), and I want to write a piece of code that checks for all cases where this value is 3 days or more ago. So far I have:

 

      Datetime daysago = now().addDays(-3);
      
      Case[] c = [SELECT Id, Feedback_Email_Sent_Date__c FROM Case WHERE Feedback_Email_Sent_Date__c >= daysago];

 I am currently getting an error saying daysago is an invalid token, how can I fix this?

 

Also, I would also like to ignore all records where the feedback sent date field is blank (meaning we haven't sent a feedback email), is there a simple way of doing this too?

 

Cheers for any help :)

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

In SOQL, whenever you use variables, they have to be written with a colon ":" 

 

 

Case[] c = [SELECT Id, Feedback_Email_Sent_Date__c FROM Case WHERE Feedback_Email_Sent_Date__c >= :daysago];

All Answers

vishal@forcevishal@force

In SOQL, whenever you use variables, they have to be written with a colon ":" 

 

 

Case[] c = [SELECT Id, Feedback_Email_Sent_Date__c FROM Case WHERE Feedback_Email_Sent_Date__c >= :daysago];
This was selected as the best answer
LeeMurphyLeeMurphy

Excellent, thanks for that :)