APEX FUNDAMENTALS

Apex Fundamentals

Data type :

A data type in the apex tells about what type of data can be stored in salesforce.
What is the range of data that can be stored:
       1. Primitive data type
       2. Collections
       3. Enums

1. Primitive data type :

These are the data types which are predefined by the Apex.
  • 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 variable, are initialised to null. Make sure that we initialise variable to an appropriate value before using them.

Apex primitive datatype include:-

Boolean
  • A value that can only be assigned true, false or null.
               Ex: Boolean isActive = False;
Date
  • A value that indicates a particular day date values contain no information about time. Date value must always be created with a system static method.
  • Ex: Date myDate = Date.newinstance (2013,05,15);
  • Output is 2012-05-15 00:00:00

Time and DateTime 


These are data types associated with date and time along with Date datatype. The Time data types stores time(hours, minutes, seconds and milliseconds). The Date datatypes stores dates (year month day). The DateTime datatype stores both dates and times.

Each of these classes has a newInstance method with which we can construct a particular date and time values.
  • Ex: Time t1 = newInstance(19,20,1,20);
  • Output 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 :

  • Ex: Time t2 = Datetime.now().time();

We can also manipulate the values by using a range of instance methods :

  • Ex: 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

Integer, Long, Double and Decimal : 
  • To store numeric values in a variable, declare variables variable with one of the numeric data types. Integer, Long, Double and Decimal.

Integer: 
  • A 32-bit number that doesn’t include a decimal point Integer have a minimum value of -2, 147, 467, 678 and a maximum value of 2,147, 483, 647.


Ex: Integer i = 1;

Class :
A class is a collection of data members and methods.

Example 1 :
=============================================
Class student
 {
    Integer no; //======These are data members of class
    String name; //=====
  public void getDetails() //==== This is the method of the class
  {
    system.debug(‘roll no’ + no);
    system.debug(’name’ + name);
  }
}
=============================================

Example 2 :
=============================================
Class Employee
 {
   Integer exp; //===== variable /data members of the class
   String department; //=====

 void show() //===== Method of the class
 {
    //Write the logic here
  }
}
=============================================

To define an Apex Class specify the following :

1. Access Modifiers :
  • You must use one of the access modifiers for top-level class (Public or Global).
  • You do not have to use access modifiers in the declaration of inner classes.
2. Optional definition modifiers such as Virtual, abstract.

3. Required: The keyword class followed by the class name.

4.Optional extensions : AND / OR implementation.

Syntax :
=============================================
private | public | global [virtual | abstract | with sharing | (none)]
Class ClassName [implements InterfaceNameList | (none)] [extends ClassName | (none)]
  
   {
      // The body of a class
   }

=============================================

These are the basic fundamentals of the apex, In the next episode, we will discuss sharing and without sharing in salesforce. 

WOHOOO !! YOU HAVE JUST COMPLETED APEX FUNDAMETALS EPISODE
If you like this salesforcekid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you 
Happy learning ☁️⚡️ (Learn. Help. Share.)

<< PREVIOUS                                                     NEXT >>

APEX FUNDAMENTALS APEX FUNDAMENTALS Reviewed by on Rating: 5

1 comment:

HELP !! SHARE !! SUGGEST !!

Powered by Blogger.