Welcome to my blog

I have been working with Salesforce for quite a while, so don’t hesitate to contact me if you have any questions or want some advice.

s f

Subscribe
Follow Us
h

How to use DateTime in Dynamic SOQL Query Where Condition?

 . Adminstrator  . How to use DateTime in Dynamic SOQL Query Where Condition?

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

Post a Comment