Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

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

                      ^

1 Answer

0 votes
by (32.1k points)
edited by

To make an SQL query like:

SELECT id FROM Account WHERE LastActivityDate = 30_DAYS_AGO

You can calculate the date in apex and then bind it into your query.

Are you interested in learning Salesforce from scratch! Have a look at this interesting video on Salesforce provided by Intellipaat:

As shown in Example:

date d = system.today().addDays(-30); Account [] acc= [select id from account where createdDate = :d];

Or, you can go ahead and use:

SELECT id FROM Account WHERE LastActivityDate = LAST_N_DAYS:30

LAST_N_DAYS is a sytax which is used to find out the activity in the last N days (here, N = 30)

To learn in-depth about Workflow in Salesforce, sign up for industry-based Salesforce Training!

Related questions

Browse Categories

...