Apex classes are modeled on their counterparts in Java. You’ll define, instantiate,
and extend classes, and you’ll work with interfaces, Apex class versions, properties, and
other related class concepts.
-
Classes
As in Java, you can create classes in Apex. A class is a template or blueprint from which objects are created. An object is an instance of a class. -
Interfaces
An interface is like a class in which none of the methods have been implemented—the method signatures are there, but the body of each method is empty. To use an interface, another class must implement it by providing a body for all of the methods contained in the interface. -
Keywords
Apex provides the keywords final, instanceof, super, this, transient, with sharing and without sharing. -
Annotations
An Apex annotation modifies the way that a method or class is used, similar to annotations in Java. Annotations are defined with an initial @ symbol, followed by the appropriate keyword. -
Classes and Casting
In general, all type information is available at run time. This means that Apex enables casting, that is, a data type of one class can be assigned to a data type of another class, but only if one class is a subclass of the other class. Use casting when you want to convert an object from one data type to another. -
Differences Between Apex Classes and Java Classes
Apex classes and Java classes work in similar ways, but there are some significant differences. -
Class Definition Creation
Use the class editor to create a class in Salesforce. -
Namespace Prefix
The Salesforce application supports the use of namespace prefixes. Namespace prefixes are used in managed AppExchange packages to differentiate custom object and field names from names used by other organizations. -
Apex Code Versions
To aid backwards-compatibility, classes and triggers are stored with the version settings for a specific Salesforce API version. -
Lists of Custom Types and Sorting
Lists can hold objects of your user-defined types (your Apex classes). Lists of user-defined types can be sorted. -
Using Custom Types in Map Keys and Sets
You can add instances of your own Apex classes to maps and sets.