Grails 2.x provide methods to retrieves the first and last instance of the domain class.

User.first()
User.last()

Here we can pass name of the property to sort by.

User.first('username')
User.last('username')

or

User.first([sort: 'username'])
User.first(sort: 'username')

User.last([sort: 'username'])
User.last(sort: 'username')

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