Wednesday, April 9, 2014

What is Class and How to define Class in Apex? How to created class in Apex?

A class is a template or
blueprint from which objects are created.For example, the PurchaseOrder class
describes an entire purchase order, and everything that you can do with a
purchase order. An instance of the PurchaseOrder class is a specific purchase order
that you send or receive.

A class can contain variables
and methods. Variables are used to specify the state of an object, such as the
object's Name or Type. Since these variables are associated with a class and
are members of it, they are commonly referred to as member variables. Methods
are used to control behavior, such as getOtherQuotes or copyLineItems.

To define a class, specify the
following:

1. Access modifiers:

You must use
one of the access modifiers (such as public or global) in the declaration
of a top-level class.

You do not
have to use an access modifier in the declaration of an inner class.

• Theprivateaccess modifier declares that
this class is only known locally, that is, only by this section of code. This
is the default access for inner classes—that is, if you don't specify an access
modifier for an inner class, it is considered private. This keyword can only be
used with inner classes.

• Thepublicaccess
modifier declares that this class is visible in your application or namespace.

• Theglobalaccess
modifier declares that this class is known by all Apex code everywhere. All
classes that contain methods defined with the webService keyword must be
declared as global. If a method or inner class is declared as global, the
outer, top-level class must also be defined as global.