Work with Apex Code (Beta)

Apex is a typed, object-oriented programming language that enables developers to run the flow and transaction control statements on the Lightning Platform server with calls to the Lightning Platform API. Because Apex uses syntax that looks like Java and acts like database-stored procedures, developers can add business logic to most system events, including button clicks, related record updates, and Visualforce pages. The web-service requests and triggers on objects initiate Apex code.

Apex can be stored on the platform in two different forms.

  • A class is a template or blueprint from which Apex objects are created. Classes consist of other classes, user-defined methods, variables, exception types, and static initialization code. From Setup, enter Apex Classes in the Quick Find box and then select Apex Classes.
  • A trigger is Apex code that executes before or after specific Data Manipulation Language (DML) events occur, such as before object records are inserted into the database or after records have been deleted. Triggers are stored as metadata in Salesforce. A list of all triggers in your organization is located on the Apex Triggers page in Setup.

For more information about creating Apex objects, see Apex Code Overview.

This section explains how to create and run an anonymous Apex script.