filter criterion for field ‘createdDate’ must be of type dateTime and should not be enclosed in quotes in SOQL

CreatedDate between two specific dates, but getting errors like when sending my query. For example, the query below should be giving a list of Contact from 07/20 to 07/25.

SELECT Id FROM Contact WHERE  CreatedDate >= 2014-07-20  AND  CreatedDate <= 2014-07-25

but got the Error like Below:
value of filter criterion for field ‘CreatedDate’ must be of type dateTime and should not be enclosed in quotes
here is the Answer:
CreatedDate is a Datetime field, so we need to use like following way:

Syntax: YYYY-MM-DDThh:mm:ssZ (optionally with timezones)

SELECT Id FROM Contact WHERE  CreatedDate >= 2014-07-20T00:00:00Z  AND  CreatedDate <= 2014-07-20T23:59:59Z

SELECT Id FROM Contact WHERE CreatedDate >= 2014-07-20T01:02:03Z

SELECT id, CreatedDate FROM Contact where CreatedDate < 2014-07-25T00:00:00Z.

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply

Your email address will not be published. Required fields are marked *

*