+ Start a Discussion
Rishabh Patel 1Rishabh Patel 1 

SOQL lastmodified date time within 60 minutes

How do I Write a SOQL query which selects all leads that are modified within 60 minutes from now 

Select all  the lead Lastmodified date within 60 minutes or last hour 

Raj VakatiRaj Vakati

The easiest way might be to make the following Minutes_Since_Modified__c formula:

(NOW() - LastModifiedDate) * 24 * 60

Then to query for it:

SELECT Id FROM Lead WHERE Minutes_Since_Modified__c <= 60

Datetime hourBack = Datetime.now().addMinutes(-60);
List<Lead> records = [
    SELECT Name FROM Lead
    WHERE LastModifiedDate >= :hourBack