Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOQL query WHERE Date = 30_days_ago?

How do I make a SOQL query like this?

SELECT id FROM Account WHERE LastActivityDate = 30_DAYS_AGO

This produces an error:

MALFORMED_QUERY: 
Account WHERE LastActivityDate = 30_DAYS_AGO
                      ^
like image 743
Dave S Avatar asked Mar 08 '11 22:03

Dave S


3 Answers

SELECT id FROM Account WHERE LastActivityDate = LAST_N_DAYS:30
like image 89
ScottW Avatar answered Oct 28 '22 20:10

ScottW


As you're doing this from apex, you can calculate the date in apex, then bind that into your query, e.g.

date d = system.today().addDays(-30);
Account [] acc=  [select id from account where createdDate = :d];
like image 41
superfell Avatar answered Oct 28 '22 21:10

superfell


Select Id from Account Where LastActivityDate = N_DAYS_AGO:30
like image 37
Jacob H Avatar answered Oct 28 '22 21:10

Jacob H