Apex Primitive Data Types in Salesforce
Data type: data type in the apex tells about what type of data can be stored
What is the range of the data that can be stored?
a) Primitive data types
b) Collections
c) Enums
1. Primitive data types:
These are the data types which are predefined by the apex
a) A primitive data types such as an integer, double, long, date, date time, string, id or Boolean
All primitive data types are passed by value, not by reference.
All apex variable, whether they are class member’s variables, are initialized to null. make sure that we initialize variables to appropriate values before using them.
Apex primitive data type include:
Boolean: a value that can only be assigned true, false or null
Eg: Boolean is active false;
Date: a value that indicates a particular day. date value contains no information about time, date value must always be created with a system static method.
Eg: date my date=date. New instance (2013/05/15);
Output is 2013/05/15 00:00:00;
Time and date time:
These are date type associated with dates and times along with date data type. The time data type stores times (hours, minutes, second and milliseconds). The date time data types stores dates (year month and date). The date time data type stores both dates and times.
Each of these classes has.A new instance with which we can construct particular date and time value.
Eg: time t1 = new instance (19,20,1,20);
o/p is 19:20;01
We can also create dates and times from the current clock.
Date my =datetime.now();
Date t =date.today();
The date and time classes also have instance methods for converting from one format to another
Eg: time t2 = date time.now().time();
We can also manipulate values by using a range of instance methods
Eg: Date t3 = date.today(0);
Date next =t3.adddays(30);
We will get something like this as the output.
2013-05-15 00:00:00
2013-06-16 00:00:00
No comments:
Post a Comment