4

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?

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

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 an 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
];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.