Apex Data Types include:
- Primitive
- Enum
- sObject
- Collection
Primitive Data Types:
Include the following:
- Boolean
- Date
- Date/Time
- Time
- ID
- Integer
- Long
- Double
- Decimal
- String
- Blob
- Object
Enum Data Types
- Is an abstract data type that allows you to store the values of a finite set of identifiers
- Defined using the keyword ‘enum’
- Built-in enums viz. System.StatusCode returns API error codes
- Some enum methods:
- Values() – returns a list of values for the enum
- Name() – returns the name of the enum
sObject Data Types
- Represents Objects (Standard and Custom) in Salesforce.com
- Can be either strongly typed or loosely typed
- Initialized to null by default
- Can be instantiated with <name, value> pairs
- Possible to declare variables of generic sObject data types. e.g.
- sObject obj = new Account(); //obj instantiation
- Account acct = (Account)obj; // type-casting
- sObject[] acc = new Account[0];
- List<Account> accnt = List<Account> acc; //List of Accounts
Collection Data Types
Three different collections: List, Set, Map
- A List is an ordered collection of a single type
- List<Integer> iList = new List<Integer>(); iList.add(1); iList.add(‘String’); // not allowed
- Supports common methods like add, remove, clear, get, sort, isEmpty, size
- A Set is an un-ordered collection of unique data
- Set<Integer> iSet = new Set<Integer>(); iSet.add(1); iSet.add(2); iSet.add(3); iSet.add(2); //not allowed
- Supports common methods like add, remove, clear, get, sort, isEmpty, size, remove, removeAll, contains, containsAll
- A Map (Hash-Map) is an un-ordered collection of unique keys that map to single values
- <Key, Value> pair
- Keys and Values can be of any data type including other collections from the above list
- Often used to map ID’s to sObjects
- Supports common methods like add, remove, clear, get, sort, isEmpty, size, remove, removeAll, contains, containsAll, containsKey, keySet, values, put, putAll
- Map<Integer, String> map = new Map<Integer, String>(); map.put(1, ‘One’); map.put(2, ‘Two’);
[message_box title=”Salesforce.com Certified” color=”blue”]From the small business to the large enterprise, we have solutions to help improve win rates.[/message_box]
Contact Us