+ Start a Discussion
kito kidkito kid 

records with last updated date within 1hour

I am following the code below to grab the records which has been modified within last 1 hour.

 

Select a.Id From Account a
Where a.LastModifiedDate = TODAY AND HOUR_IN_DAY(a.LastModifiedDate) > 24

 

But , I can't get any records.

Any idea to get something like this.

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Hi kito,

 

You have to write following SOQL query for display last updated record within 1hour.

 

Select a.Id From Account a Where a.LastModifiedDate = TODAY AND HOUR_IN_DAY(a.LastModifiedDate) > 1

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

All Answers

hitesh90hitesh90

Hi kito,

 

You have to write following SOQL query for display last updated record within 1hour.

 

Select a.Id From Account a Where a.LastModifiedDate = TODAY AND HOUR_IN_DAY(a.LastModifiedDate) > 1

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

This was selected as the best answer
KaityKaity

DateTime dt = System.Now().addHours(-1);
List<Account> accLst = [SELECT Id, Name FROM Account WHERE LastModifiedDate>=:dt];
System.debug(‘@@@List Of all Account records created within last 12 hours@@@’ + accLst);

 

 

Hitesh: I've a query- Why you are using LastModifieddate = Today? It may be there in different days but within 1 hour?

 

Thanks,

Kaity

Luís SoaresLuís Soares
The selected solution won't work at 00h:10min right?
Trey McGinnisTrey McGinnis
The selected answer does not do what was asked. It returns records that have been modified today at any hour except 12-1AM (when HOUR_IN_DAY returns 1).
porter.mikeporter.mike
USE Kaity's ANSWER
Patrick Shea 25Patrick Shea 25
Thanks for the info. This solution still works 7 years later!  ;)