If you already have the objects in a List, you can look at the List Operations and use Head to get the first object in the List. To get the last is a bit trickier, but one way is to reverse the list and take the Head again.
https://docs.mendix.com/refguide/list-operation#3-1-3-unary
Hope this helps.
Hi Christo
By using ‘Retrieve from database’, you can set the XPath to your desired association and then select the range ‘First’ and sort on the attribute of your choice. When you select Descending on createddatetime, you get the newest item. When you select Ascending on createddatetime, you get the oldest item. For example. You can always add an extra attribute of chose, should want to be able to manually set the order.
I hope this helps you!
Kind regards,
Leander