function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JBabuJBabu 

Querying the records modified within the 15 minutes

Hi,

 

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.

 

Thanks,

Babu.

chris.noechris.noe

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)

 

JBabuJBabu

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

chris.noechris.noe

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
SELECT Id
FROM Account
WHERE CreatedDate > 2005-10-08T01:02:03Z

You need to query in above format.
JBabuJBabu

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

JBabuJBabu

@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.
sfdcfoxsfdcfox

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.

JBabuJBabu

Hi,

 

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..

sandeep@Salesforcesandeep@Salesforce

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)