I know that you get today's date like this:
What would be the best solution to get yesterday's date?
Just use addDays with a negative value:
You can use the
addDays() functions as already mentioned, but SOQL has a Date Literal Already set up for this, and might be a bit more simple. You just simply have to query for a date of
list<Account> accounts = [Select Id From Account Where CreatedDate = YESTERDAY];
Here is the documentation for Date Literals. Although the
addDays() works, this seems a bit more clean in some use cases.
This also works
System.today() - 1