Skip to main content
added 189 characters in body
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

You can add a couple clauses:

SELECT Date__c FROM Object__c
WHERE Date__c < TODAY
ORDER BY Date__c DESC
LIMIT 1
  • The ORDER BY clause makes sure you get the most recent result first.
  • The LIMIT clause makes sure you only get one result.

So if you wanted a method that returns just the Date value it would look like:

public static Date getMostRecentXBeforeToday()
{
    return [/*query*/].Date__c;
}

You can add a couple clauses:

SELECT Date__c FROM Object__c
WHERE Date__c < TODAY
ORDER BY Date__c DESC
LIMIT 1
  • The ORDER BY clause makes sure you get the most recent result first.
  • The LIMIT clause makes sure you only get one result.

You can add a couple clauses:

SELECT Date__c FROM Object__c
WHERE Date__c < TODAY
ORDER BY Date__c DESC
LIMIT 1
  • The ORDER BY clause makes sure you get the most recent result first.
  • The LIMIT clause makes sure you only get one result.

So if you wanted a method that returns just the Date value it would look like:

public static Date getMostRecentXBeforeToday()
{
    return [/*query*/].Date__c;
}
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

You can add a couple clauses:

SELECT Date__c FROM Object__c
WHERE Date__c < TODAY
ORDER BY Date__c DESC
LIMIT 1
  • The ORDER BY clause makes sure you get the most recent result first.
  • The LIMIT clause makes sure you only get one result.