Velocity Snippets #1: Sorts and seeks
The idea is for Snippets posts to be code-centric as opposed to blather-centric. Copypasta with minimal commentary… let's see how it goes!
ArrayLists in brief
As you advance with Velocity, you'll make heavy use of ArrayLists, that is, arrays of objects.
ArrayLists are created automatically by Marketo when you access Custom Objects (as <CustomObjectName>List), and you can also create your own using the simple literal syntax you see throughout my code:
#set( $myList = [ 1, 11, 22 ] )
#set( $myOtherList = [
{
"id" : 123,
"prop1" : "apple"
},
{
"id" : 456,
"prop2" : "orange"
}
] )
Sorting ArrayLists by primary properties (think timestamps) and grabbing the most important item are both things you'll want to do — trust me!