Notes
Apex supports the following data types −
-
Primitive Data Types (Integer, Double, Long, Date, Datetime, String, ID, or Boolean)
-
Collections (Lists, Sets and Maps) (To be covered in Chapter 6)
-
sObject
-
Enums
-
Classes, Objects and Interfaces
Primitive Data Types
Integer:
A 32-bit number that does not include any decimal point.
The value range for this starts from -2,147,483,648 and the maximum value is up to 2,147,483,647.
Integer myAge = 38;
system.debug('I am '+ myAge + ' years old.');
Long
This is a 64-bit number without a decimal point.
This is used when we need a range of values wider than those provided by Integer.
Long myLong = 21474838973344648L;
system.debug(myLong);
Double:
Doubles are 64-bit numbers that range from -2^63 to 2^63-1.
Double myDouble =124532.32;
System.debug(myDouble);
Decimal:
A number that includes a decimal point.
Currency fields are automatically assigned the type decimal.
Decimal totalCost = 49.99;
System.debug(totalCost);
Boolean:
This variable can either be true, false or null. Many times, this type of variable can be used as flag in programming to identify if the particular condition is set or not set.
Boolean Status;
Status = true;
System.debug(Status);
Date
This variable type indicates a date. This can only store the date and not the time. For saving the date along with time, we will need to store it in variable of DateTime.
Date examDate = date.today();
System.debug('My exam date is '+examDate);
String
String is any set of characters within single quotes. It does not have any limit for the number of characters. Here, the heap size will be used to determine the number of characters. This puts a curb on the monopoly of resources by the Apex program and also ensures that it does not get too large.
String myName = 'Engin Basturk';
System.debug('My name is '+myName);
ID:
Any valid 18-character Lightning Platform record identifier.
ID id='00300000003T2PGAA0';
System.debug(ID);