如何进行这样的 SOQL 查询?
SELECT id FROM Account WHERE LastActivityDate = 30_DAYS_AGO
这会产生一个错误:
MALFORMED_QUERY:
Account WHERE LastActivityDate = 30_DAYS_AGO
^
如何进行这样的 SOQL 查询?
SELECT id FROM Account WHERE LastActivityDate = 30_DAYS_AGO
这会产生一个错误:
MALFORMED_QUERY:
Account WHERE LastActivityDate = 30_DAYS_AGO
^
SELECT id FROM Account WHERE LastActivityDate = LAST_N_DAYS:30
当您从 apex 执行此操作时,您可以计算 apex 中的日期,然后将其绑定到您的查询中,例如
date d = system.today().addDays(-30);
Account [] acc= [select id from account where createdDate = :d];
Select Id from Account Where LastActivityDate = N_DAYS_AGO:30
LAST_WEEK
并且LAST_MONTH
也很容易并且工作良好。
SELECT id FROM Account WHERE LastActivityDate > LAST_MONTH
有关更多数据,请查看此链接: http: //www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm
由于它是 30 天前,你可以使用这个 -
SELECT ID FROM Account WHERE LastActivityDate < LAST_N_DAYS:30
您的查询时间段位于提供 SFDC 最好使用它的日期文字中,因为指定的时间是一个广泛的数字,您只需要提供天数并相应地使用运算符,即 '=' ,'>' 或'<'
LAST_N_DAYS:n LAST_N_WEEKS:n LAST_N_MONTHS:n LAST_N_YEAR:n
NEXT_N_DAYS:n NEXT_N_WEEKS:n NEXT_N_MONTHS:n NEXT_N_YEAR:n
如果您只提供它所在的天数/月数,您的查询看起来会更简单。
SELECT id FROM Account WHERE LastActivityDate = LAST_N_MONTHS:1
或者
SELECT id FROM Account WHERE LastActivityDate = LAST_N_DAYS:30
谢谢,OQ。
The page of SOQL date functions appears to have moved here: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm
To clarify, SOQL allows a date field (e.g. LastActivityDate) to be compared against a range of dates using a comparison operator. So "LastActivityDate = LAST_MONTH" is equivalent to saying that the date is greater than or equal to the start of the first day of the previous month AND less than or equal to the end of the last day.