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
mark_pamark_pa 

Querying the API for records modified within the last hour

Hello all,

 

We are trying to get the API to query our data to get records modified within the last hour. When tested, we receive empty strings. The best we have gotten to work so far is getting records modified yesterday or today.

 

Anyone know of a way to get records modified within the last hour?

 

Thanks,

 

Mark 

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

If you are just using the SOQL language directly then I think the Date Literals supplied as part of the language only have granularity down to a Day level... as you have found.  

 

If you want to hard code a specific DateTime value then you can obviously just write SOQL like:

 

select name from Opportunity where SystemModstamp > 2010-01-18T00:00:00Z

 

but that doesn't help with creating a rolling window.

 

 

So, since it seems that you're doing polling of some kind, so I presume you're doing it from some language, Apex, or through the API, or something.  Either way, whatever mechanism you're using should give you a way to build Datetime values based on an offset from the current time that you can use to build your query.

 

If you're using Apex, I think it would be:

 

List<Opportunity> Opps = new List<Opportunity>([select name from Opportunity

     where SystemModstamp >  :Datetime.now().addMinutes(-60);

 

Also note: if you're doing polling via the API, you might want to look into the getUpdated and getDeleted calls... they are there to help with the polling scenario.

 

Best, Steve.

All Answers

werewolfwerewolf
Have you tried getUpdated()?
SteveBowerSteveBower

If you are just using the SOQL language directly then I think the Date Literals supplied as part of the language only have granularity down to a Day level... as you have found.  

 

If you want to hard code a specific DateTime value then you can obviously just write SOQL like:

 

select name from Opportunity where SystemModstamp > 2010-01-18T00:00:00Z

 

but that doesn't help with creating a rolling window.

 

 

So, since it seems that you're doing polling of some kind, so I presume you're doing it from some language, Apex, or through the API, or something.  Either way, whatever mechanism you're using should give you a way to build Datetime values based on an offset from the current time that you can use to build your query.

 

If you're using Apex, I think it would be:

 

List<Opportunity> Opps = new List<Opportunity>([select name from Opportunity

     where SystemModstamp >  :Datetime.now().addMinutes(-60);

 

Also note: if you're doing polling via the API, you might want to look into the getUpdated and getDeleted calls... they are there to help with the polling scenario.

 

Best, Steve.

This was selected as the best answer