Salesforce Apex resembles Java programming language, but it uses objects to represent primitives and also offer pre-built methods for commonly performed tasks. Here is a list of commonly used primitive object methods, and functions that can be used with Apex programming language.
- What is the best way to test if a String is empty? Apex String class has an isBlank() method which returns true if the specified String is white space, empty (''), or null; otherwise, returns false. The string class also has isEmpty(), isNotBlank() and isNotEmpty() methods. Unlike isBlank(), the isEmpty() method returns false if the specified String is white space.
- What is the difference between the array and list? In Apex, the array and list are same with essentially same behavior with different syntax. Although you may initialize an array with a fixed size, you can always grow dynamically by adding more elements to an array. Also, array syntax doesn't allow multi-dimensional array so a list must be used to represent a multi-dimensional array.
1. Syntax for creating a List and adding an element. List
mylist = new List (); mylist.add('One'); 2. Syntax for creating an Array and adding an element String myarray = new String; myarray = 'One'; 3. Syntax for creating a multi-dimensional List and adding an element List
> mlist = new List
mylist = new List (); mylist.add('One'); mlist.add(mylist);