Primitive Data Types
Here we have primitive data types such as Integer, Double, Long, Date, Date Time, String, ID, and Boolean etc..
– All primitive data types are passed by value, not by reference.
– All Apex variables, whether they are class member variables or number variables are initialized to null. Make sure that we initialize variables to appropriate values before using them.
Boolean: A value that can only be assigned true, false or null.
Example: Boolean is Active = True;
Date: A value that indicates a particular day. Date value contain no information about time. Date value must always be created with a system static method.
Example: Date dt = Date.newInstance(2014, 06, 01);
Output is : 2014-06-01 00:00:00
Time and Date Time: Data types associated with dates and times along with Date data type. The time data types stores times( Year, month and day). The date time data type stores both dates and times.
Each of these classes has a newInstance method with which we can construct particular data and time values.
Example: Time t = Time.newInstance(11,30,3,3);
Output is: 11:30:03.003Z
– we can also create dates and times from the current clock.
Example 1: DateTime dt = DateTime.now();
Output is : 2014-06-01 06:29:20
Example 2: Date dt1 = Date.today();
Output is: 2014-06-01 00:00:00
– The date and time classes also have instance methods for converting from one format to another.
Time t = DateTime.now().time();
Output is: 12:15:01.975Z
– We can also manipulate the values by using a range of instance methods.
Date dt = Date.today();
Date dt30 = dt.addDays(30);
Output is : dt value = 2014-06-01 00:00:00
dt1 Value = 2014-07-01 00:00:00
Integere: A 32 bit number that doesn’t include a decimal point. Integer has a minimum value 0f -2,147,483,648 and maximum value of 2,147,483,647.
Example: Integer i=1;
Long: A 64 bit number that does n’t includes a decimal point. Long has a minimum value of -2^63 and a maximum value of 2^63-1.
Example: Long L = 2145335687L;
Double: A 64 bit number that does n’t includes a decimal point. Long has a minimum value of -2^63 and a maximum value of 2^63-1.
Example: 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.
Example: Decimal dec = 19.23
Null Variables: If we declare a variable and don’t initialize it with a value, it will be null. Null means the absence of a value. We can also assign null to any variable declared with primitive type.
Both of below statements result in a variable set to null.
String: Strings are set of characters and are enclosed in single quotes. They store text values such as a name or an address.
Example: String s1 = ‘Salesforce tutorial’
We can also create strings from the values of other types, such as dates, by using the string static method value of().
Apart from these primitive data types in salesforce we have Sobject types (Salesforce object).