Salesforce List Methods Guide
Before I get into describing and explaining any of the Salesforce list methods available (and heck no we’re not going to go over all of them), we’re going to talk about what lists and arrays actually are, and how they work. This is a very programming concept, so brace for some technical stuff here. If you’re not a programmer, then this one’s not incredibly relevant to you. So, before the Salesforce list methods, we’re going to look at what it really is. Ok, first, understand that in programming, sometimes a value must be addressed which can have varied values inside, never predictable. These are called variables, and they represent an unknown value. Now, there exists a yet more complex idea based off of this, which is the concept of multiple values represented by a single variable identity. These were originally called arrays, and worked kind of like a grid, or something like that. A specific value was addressed or written to by its element number in this collection. Modern languages have built a better array, known as a list (or vector in some languages). The list is a collection of values, allowing the handling of multiple parallel things, sorting, acting on a series and the like. It also works as a scalable variable, when you know there will be many, but never exactly how many. But, with a stack of values like this, it must be hard to use, right? No, not really. The first thing to remember is that you count from zero, not one, when you address an element number. Beyond that, know the methods that can sort and manipulate these elements easily. These are just a few. Add – This method adds an element to a list. You can, one at a time, add elements (new values or storing existing external ones) and even specify the index number to add it at. Clear – This method allows you to wipe the contents of a list. This is very useful, remember to use this to be efficient. Clone – This is also going to be way more useful than you know. It creates a duplicate of itself as a new list. Get – This is the method (function technically) which retrieves a value from a location in a list. Kind of need this one! IsEmpty – Invoking this method will return to you a True or False value, as to whether a list has contents or not. Remove – This is how you remove an element. Set – This one writes a value to a location. Also need this one. Size – This will retrieve the number of elements a list has. Sort – Sorts the contents in various orders, which, like Clone, is far more useful than you yet know. You know what? We went over all but a few of the Salesforce list methods here, way more than I thought was possible. It doesn’t take much to explain what these particular ones do, and the few we didn’t cover here are kind of weird, complex and not commonly used. I hope this has helped you to understand lists a little better, because as a programmer, it’s one of the concepts you’ll be using a lot.