Salesforce Apex FAQ

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

  BENCHMARKS  
Loading Time: Base Classes  0.0060
Controller Execution Time ( Welcome / View )  0.0420
Total Execution Time  0.0640
  GET DATA  
No GET data exists
  MEMORY USAGE  
6,348,696 bytes
  POST DATA  
No POST data exists
  URI STRING  
salesforce-apex-faq
  CLASS/METHOD  
welcome/view
  DATABASE:  wte (CI:$db)   QUERIES: 119 (0.0196 seconds)  (Show)
  DATABASE:  wte (Ion_auth_model:$master)   QUERIES: 0 (0.0000 seconds)  (Hide)
No queries were run
  HTTP HEADERS  (Show)
  SESSION DATA  (Show)
  CONFIG VARIABLES  (Show)