To query records created today or yesterday in Salesforce, filter on the CreatedDate field with a date literal: WHERE CreatedDate = TODAY returns today’s records and WHERE CreatedDate = YESTERDAY returns yesterday’s. Both are SOQL date literals, so you write them without quotes, and they work for any standard or custom object that has a CreatedDate field.
In this tutorial, I will show how to use the SOQL created date filters for today, yesterday and the last N days, how CreatedDate differs from LastModifiedDate and SystemModstamp, how to sort by created date, how to find deleted records from the recycle bin, and what happens with time zones. Every query runs in the Developer Console, in Workbench or in Apex.