Trying to filter data that is returned to me by the termination year. If any data that is pulled and has a termination date older then five years I do not want it to show up.

public static List<date> filter(List<date> results) {
    List<date> filtered = new List<date>();
    Date t = Date.today();
    for (date r : results) {
        Date d = r.lastModifiedDate;
        if (date == 'year') {
            if (d > t.addYears(-5)) {
        } else {
            // Add all to the list if no filter selected
    return filtered;

I'm receiving two errors right now.

"Variable does not exist: lastModifiedDate" "Variable does not exist: date"

  • 4
    results list is of type date , and Date object does not contain lastModifiedDate – Pranay Jaiswal Aug 5 '19 at 16:31
  • @Gevin for which object you are trying to do this? – rahul gawale Aug 5 '19 at 16:40
  • the object I am trying to pull this data from is called TerminationDate__c – Gevin Aug 5 '19 at 17:05
  • 1
    I think that showing us some details about how this filter() method is being called (and how you're getting the data you're passing into it) would help. The documentation on SOQL Date Literals will probably help you here (and you could probably use the undocumented N_YEARS_AGO:n literal). – Derek F Aug 5 '19 at 17:24

Your Answer

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

Browse other questions tagged or ask your own question.