Salesforce Apex FAQ

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.

  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 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.
  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);
    

Comments

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.