0 votes
1 view
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 (31.6k 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)

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...