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
SurenderSurender 

Need SOQL to retrive all the opportunities created an hour ago

Hi,

 

Can someone post SOQL query in apex to retrive all the opportunities created an hour ago.

 

Regards

Surender

Best Answer chosen by Admin (Salesforce Developers) 
UVUV

Can you pls mark it as a solution for the other's benifit...

All Answers

Chamil MadusankaChamil Madusanka

Try this,

 

datetime myDateTime = datetime.now().addHours(-1);

List<Opportunity> oppList = [Select id, Name FROM Opportunity where CreatedDate =: myDateTime];

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

UVUV

It should be like this-

datetime myDateTime = datetime.now().addHours(-1);

List<Opportunity> oppList = [Select id, Name FROM Opportunity where CreatedDate >=: myDateTime];
system.debug(oppList);

SurenderSurender

Hi,

 

It worked for me like below..

 

datetime myDateTime = datetime.now().addHours(-1);

List<Opportunity> oppList = [Select id, Name FROM Opportunity where CreatedDate <=: myDateTime];
system.debug(oppList);

 

Thanks for your replies..

 

Regards

G. Surender

UVUV

Can you pls mark it as a solution for the other's benifit...

This was selected as the best answer