Apex Data Types
A data type is a classification of the type of data that a variable or object can hold in computer programming. Data types are an important factor in virtually all computer programming languages, including C#, C++, JavaScript, Visual Basic. and Apex. Apex programming language supports the following data types.
- Primitive Data types
- Collections
- Enum
Primitive Data types:
Primitive data types are the data types which are predefined by the apex. All the primitive data types are passed by value,not passed by reference. All apex variables whether they are class member variables are initialized to null make sure we initialize variables to appropriate values before using them. Following are the apex primitive data types.
Boolean:
A value that are assigned True , False or Null.
Example: boolean isActive=true;
Date:
A value that indicates a particular Day. Date values does't contain information about time. Date values always must be created by system static methods. The date format is like Year-Month-Day.
Example: Date myday=Date.newInstance(2015,03,26);
DateTime:
It's advanced to date. A value that indicates a particular day and time, such as a timestamp. The time format is like Hours-Minutes-Seconds-Milliseconds.
Example: DateTime myDaytime=newInstance(2015,03,26, 20,25,56,02);
Decimal:
A number that include a decimal point.Decimal is an arbitrary Precision number.
Example: Decimal dec=98.00;
Double:
A 64-bit number that does't include a decimal point. Double have a minimum value of -263 and a maximum value of 263.
Example: Double d=5.1245d;
Integer:
A 32-bit number that does't include a decimal point. Integers have a minimum value of -2,147,483,648 and a maximum Value of 2,147,483,647.
Example: Integer i=0;
ID:
Any valid 18-character Force.com record identifier.
Example: ID id='00300000003T2PGSR4';
Long:
A 64-bit number that does't include a decimal point. Long have a minimum value of -263 and a maximum value of 263.
Example: Long l=1312123146L;
Null:
If we declare a variable and does't initialize it with a value, it will be null. Null means absence of value.
Example: Integer i;
Boolean b=Null;
Above both of the statements are nulls.
String:
Strings are set of characters and are enclosed in a single quotes.They stores text values like name,address ect..
Example: String Name='Nagarjun';
S-object:
S-objects ( Salesforce Objects) are standard or custom objects that stores data into force.com data base. we can refer sobjects and their fields by their api names.
Example: Account, Contact, Student__c
Account Acc= new Account();
Student Std = new Student();