Primitive Type Keyword
Below are the primitive data type keywords used in apex langue to declare variables.
1. Blob
This data type represents binary data stored as a single object.
Example
Blob b1 = Blob.valueof('idea');
2. Boolean
This data type represents Value that can only be assigned true, false, or null.
Example:
Boolean isvar = true;
3. Date
This data type represents particular day.
Example:
Date myDateVar = Date.today(); Date weekStart = myDateVar.toStartofWeek();
4. Datetime
This data type represents particular time and date.
Example:
Datetime myDateTimeVar = Datetime.now(); Datetime newd = myDateTimeVar. addMonths(5);
5. Decimal
This data type represents Number that includes a decimal
point. Decimal is an arbitrary precision number.
Example:
Decimal myVar = 12.4567; Decimal divDecVar = myVar.divide(7, 2, System.RoundingMode.UP); system.assertEquals(divDecVar,1.78);
6. Double
Represents 64-bit number that includes a decimal point. Minimum value -2^63. Maximum value of 2^63-1.
Example:
Double d=3.14159;
7. ID
Represents 18-character Force.com record identifier.
Example:
ID id='00300000003T2PGAA0';
8. Integer
32-bit number that doesn’t include a decimal point. Minimum value
-2,147,483,648 — maximum value of 2,147,483,647
Example:
Integer i = 1;
9. Long
Represents 64-bit number that doesn’t include a decimal point. minimum value of -263 — maximum value of 263-1.
Example:
Long l = 2147483648L;
10. String
Represents Set of characters surrounded by single quotes.
Example:
String s1 = 'Hello';
11. Time
Represents particular time.
Example:
Time myTimeVar = Time.newInstance(18, 30, 2, 20); Integer myMinutes = myTimeVar. minute();
List Type Keywords
Below are the Collection Type keyword used in Apex:
1. List
Ordered collection of typed primitives, sObjects, objects, or collections that are distinguished by their indices.
Example:
// Create an empty list of String List<String> my_list = new List<String>(); My_list.add('first'); String x = my_list.get(0); // Create list of records from a query List<Account> accs = [SELECT Id, Name FROM Account LIMIT 1000];
2. Map
Collection of key-value pairs where each unique key maps to a single value. Keys can be any primitive data type, while values can be a primitive, sObject,
collection type, or an object.
Example:
Map<String, String> mys = new Map<String,String>(); Map<String, String> mys = new Map<String, String>{'a' => 'b', 'c' => 'd'.toUpperCase()}; Account myAcct = new Account(); Map<Integer, Account> m = new Map<Integer, Account>(); m.put(1, myAcct);
3. Set
Unordered collection that doesn’t contain any duplicate elements.
Example:
Set<Integer> s = new Set<Integer>(); s.add(1); s.add(1); System.assert(s.size()==1);