How to use DateTime in Dynamic SOQL Query Where Condition?
How to Use Datetime in Dynamic SOQL Query in where Condition?
There are many place we use DateTime in Where condition. There are many people having trouble to use developer console or dynamic SOQL query to pull data based on DateTime Field.
Salesforce always store date/datetime field in to GMT format. GMT Format is “yyyy-MM-ddThh:mm:ssZ”.
User Case: you may want to check how many account create past 5 days. you don’t have any Date Literals to accomplish above use case. You need to build your custom logic like below
below query for past few days :How to Use Datetime in Dynamic SOQL Query in where Condition?
SELECT Id FROM Account WHERE CreatedDate > 2016-09-10T00:00:00Z
below query for particular day:
SELECT Id FROM Account WHERE CreatedDate >= 2016-09-10T00:00:00Z and CreatedDate <= 2016-09-10T23:59:59Z
0 Comments