6

we have Order__c as custom object. we are trying to extract the past 30 minutes record. where LastModifiedDate=TODAY and HOUR_IN_DAY(LastModifiedDate) > 0.5 is not working

We tried SOQL :

 SELECT count() FROM Order__c  where LastModifiedDate=TODAY and HOUR_IN_DAY(LastModifiedDate) > 0.5

HOW DO I FETCH PAST 30 minute records only using Where clause filter?

2
  • Is Apex an option?
    – Adrian Larson
    Commented Aug 9, 2016 at 19:40
  • No. Only we have to write in pure SOQL . because data integration tool understand only SOQL while migrating the record.
    – Sylphes
    Commented Aug 9, 2016 at 19:42

1 Answer 1

12

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 Account WHERE Minutes_Since_Modified__c <= 30

If you can use Apex, then use a Datetime instance.

Datetime halfHourBack = Datetime.now().addMinutes(-30);
List<MyObject__c> records = [
    SELECT count() FROM MyObject__c
    WHERE LastModifiedDate >= :halfHourBack
];

If not, you can query the literal value as long as you can construct it using ISO 8601. For example at 12:30 PM it would look like:

List<MyObject__c> records = [
    SELECT count() FROM MyObject__c
    WHERE LastModifiedDate >= 2016-08-09T12:00:00Z
];
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .