You can easily Query records created Today or Yesterday or which are Last Modified Today or Yesterday. No need to jump on dates and making dynamic queries to create the current date or yesterday’s date. You can even query records whose closedate is Tomorrow. Salesforce provides an easy way to query it. For this, you just need to append TODAY or YESTERDAY or TOMORROW in your WHERE clause of the query.
Salesforce provides so many Date Literals to directly use in your query. Check Here.
Check out these examples for easy understanding.
Accounts created Today:
1 2 3 |
SELECT Id, Name, Type, Phone FROM Account WHERE CreatedDate = TODAY |
Account Last Modified Today:
1 2 3 |
SELECT Id, Name, Type, Phone FROM Account WHERE LastModifiedDate = TODAY |
Opportunities whose CloseDate is Tomorrow:
1 2 3 |
SELECT Id, stage FROM Opportunity WHERE CloseDate = TOMORROW |
Records created Yesterday:
1 2 3 |
SELECT Id, Name, Type, Phone FROM Account WHERE CreatedDate = YESTERDAY |
Records Last Modified Yesterday:
1 2 3 |
SELECT Id, Name, Type, Phone FROM Account WHERE LastModifiedDate = YESTERDAY |
Accounts created Yesterday AND Modified Today:
1 2 3 |
SELECT Id, Name, Type, Phone FROM Account WHERE CreatedDate = YESTERDAY AND LastModifiedDate = TODAY |
Accounts either created Yesterday or Today:
1 2 3 |
SELECT Id, Name, Type, Phone FROM Account WHERE CreatedDate = TODAY OR CreatedDate = YESTERDAY |
Also Check:
For any queries or suggestions, comment below.
Cheers … Happy Coding … 🙂