Apex uses the same primitive data types as the SOAP API. All primitive data types are passed by value, not by reference.
All Apex variables, whether they’re class member variables or method variables, are initialized to null. Make sure that you initialize your variables to appropriate values before using them. For example, initialize a Boolean variable to false.
- Integer: A 32-bit number that does not include decimal point. Integers have a minimum value of -2, 147,483648 and maximum value of 2,147,483648.
Integer i = 1;
- Long: A 64 bit number that doesn’t includes a decimal point. Long has a minimum value of -2^63 and a maximum value of 2^63-1.
Long l = 2147483648L;
- Double: A 64 bit number that doesn’t includes a decimal point. Long has a minimum value of -2^63 and a maximum value of 2^63-1.
Double d = 3.14159;
- Decimal: A number that includes a decimal point. Decimal is an arbitrary precision number. Currency fields are automatically assigned the type decimal.
Double d = 256.32;
- String: Strings are set of characters and are enclosed in single quotes. They store the text values such as name or an address.
String str = 'Biswajeet Samal';
- Date: A value that indicates a particular day. Date values contain no information about time. Date values must always be created with system static method.
Date myDate = Date.newinstance(2015, 09, 14); Output: 2015-09-14 00:00:00
- Time: A value that indicates a particular time. Time values must always be created with a system static method.
Time tm = newInstance(10,12,5,11); Output: 10:12:05
- Date Time: These are data types associated with dates and times along with Date data type. The time data type stores times (hours, minutes, second and milliseconds). The Date data types stores dates (Year month and day). The time data type stores both dates and times.
Each of these classes has a newInstance method with which we can construct particular date time values.
Date dt = Datetime.now();
- Id: Any valid 18-character Force.com record identifier.
If you set ID to a 15-character value, Apex converts the value to its 18-character representation. All invalid ID values are rejected with a runtime exception.
- Boolean: A value that can only be assigned true, false, or null.
Boolean isValid = true;
- Blob: A value that can only be assigned true, false, or null.
It stores files data in binary format.