+ Start a Discussion

Querying the records modified within the 15 minutes



I want to query the records which are modified with last 15 mins.

Please let me know the SOQL query for the same. I tried


select name from Opportunity

     where SystemModstamp >  Datetime.now().addMinutes(-15)


it did not work.


I want to run the query using force.com explorer/workbench

Please let me know if there is any other method to get this.





Are you getting a syntax error or is it not returning the results you expect?  You need a ":" in from of Datetime in your query filter.  Try:


select name from Opportunity where SystemModstamp > :Datetime.now().addMinutes(-15)



I am getting below message :
MALFORMED_QUERY: unexpected token: 'Datetime.now'


And if I used colon :

select name from Opportunity    where SystemModstamp >  :Datetime.now().addMinutes(-15)


I am getting message that

Bind variables are only allowed in Apex code


When I run the following code in Eclipse (Execute Anonymous), it returns results with no errors.  Where are you trying to run this SOQL query from?


List<Opportunity> oppList = [select name from Opportunity where SystemModstamp > :Datetime.now().addMinutes(-15)];


Bhawani SharmaBhawani Sharma
FROM Account
WHERE CreatedDate > 2005-10-08T01:02:03Z

You need to query in above format.

I am trying to run this query from eclipse/force.com explorer/workbench


@Tech Force - I need dynamic query. Which needs to return for data for every 15 mins. I need to include this in the querystring for SOAP request.

There is no "dynamic" filter for minute granularity in the SOAP API. You must provide a correctly formatted date/time, as outlined by a prior response.




We got this by creating a formula field with if condition : if current time - last modified time is < = 15 mins, it returns true else false. We use this field in where clause of the query..


It is very pretty simple to execute

Please use this SOQL if your object is Opportunity otherwise just put your object name in place of Opportunity.
List<Opportunity> Optylist = new List<Opportunity>();
Optylist = [select name from Opportunity where SystemModstamp > :Datetime.now().addMinutes(-15)];

Martin Johnson 9Martin Johnson 9
Can something similar be done in DATALOADER ??  I have tried below with the error mentioned above
"Bind variables are only allowed in Apex code"
Select Id, Name FROM Account WHERE CreatedDate >=  :Datetime.now().addMinutes(-60)
Select Id, Name FROM Account WHERE SystemModstamp >= :Datetime.now().addMinutes(-60)