Salesforce Apex FAQ

Salesforce Apex resembles Java programming language, but it uses objects to represent primitives and also offers 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.

  1. 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.
  2. What is the difference between the array and list? In Apex, the array and list are the same with essentially the 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 arrays so a list must be used to represent a multi-dimensional array.
  3. 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[0] = 'One';
    
    3. Syntax for creating a multi-dimensional List and adding an element
    List> mlist = new List>();
    List mylist = new List();
    mylist.add('One');
    mlist.add(mylist);
    

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment