(Quick Reference)

last

Purpose

Retrieves the last instance of the domain class.

Examples

Given the domain class:

class Person {
    String firstName
    String lastName
    Integer age
}
// retrieve the last person ordered by the identifier
def p = Person.last()

// retrieve the last person ordered by the lastName property
p = Person.last(sort: 'lastName')

// retrieve the last person ordered by the lastName property
p = Person.last('lastName')

Parameters:

  • sort (optional) - The name of the property to sort by

See also:

Note that the first() and last() methods are not supported on domain classes which use a composite primary key.