A class is a template or blueprint from which objects are created. An object is an instance of a class. This is the standard definition of Class. Apex Classes are similar to Java Classes.

For example, InvoiceProcessor class describes the class which has all the methods and actions that can be performed on the Invoice. If you create an instance of this class, then it will represent the single invoice which is currently in context.

There are three ways to create classes in Salesforce:

  1. Developer console (File -> New -> Apex Class)
  2. Force.com IDE (File -> New -> Apex Class)
  3. Apex class detail page (Setup -> Apex Classes)

The followign is the syntax for defining a class:

private | public | global
[virtual | abstract | with sharing | without sharing]
class ClassName [implements InterfaceNameList] [extends ClassName] {
   // Classs Body
}

So it has the access modifiers private/public/global:

  • Private means it is only known locally.
  • Public means it’s accessible to your organisation (this is most common).
  • Global means it’s accessible by all Apex code, irrespective of organisation.

There are sharing modes:

  • With sharing. I think this means that it will only act on records that the user executing the class has access to.
  • Without sharing. Act on records irrespective of whether the user has access to them.
  • Virtual. Class can be extended and overrides are allowed.
  • Abstract. Only contains the signature of the method and not the actual implementation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s