SOQL query WHERE Date = 30_days_ago?

How to make a SOQL query next?

SELECT id FROM Account WHERE LastActivityDate = 30_DAYS_AGO 

This causes an error:

 MALFORMED_QUERY: Account WHERE LastActivityDate = 30_DAYS_AGO ^ 
+6
apex-code salesforce soql
source share
5 answers

As you do this from the top, you can calculate the date on the top and then bind it to your query, for example.

 date d = system.today().addDays(-30); Account [] acc= [select id from account where createdDate = :d]; 
+13
source share
 SELECT id FROM Account WHERE LastActivityDate = LAST_N_DAYS:30 
+15
source share
 Select Id from Account Where LastActivityDate = N_DAYS_AGO:30 
+7
source share

LAST_WEEK and LAST_MONTH also simple and work well.

 SELECT id FROM Account WHERE LastActivityDate > LAST_MONTH 

For more information, follow this link: http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm

0
source share

The SOQL date functions page is displayed 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 you to map a date field (for example, LastActivityDate) to a date range using the comparison operator. Therefore, "LastActivityDate = LAST_MONTH" is equivalent to the fact that the date is greater than or equal to the beginning of the first day of the previous month and less than or equal to the end of the last day.

0
source share

All Articles