Introducing Apex
Salesforce has changed the way organizations do business by moving enterprise applications that were traditionally client-server-based into an on-demand, multitenant Web environment, the Force.com platform. This environment allows organizations to run and customize applications, such as Salesforce Automation and Service & Support, and build new custom applications based on particular business needs.
While many customization options are available through the Salesforceuser interface, such as the ability to define new fields, objects, workflow, and approval processes, developers can also use the SOAP API to issue data manipulation commands such asdelete(), update() orupsert(), from client-side programs.
These client-side programs, typically written in Java, JavaScript, .NET, or other programming languages grant organizations more flexibility in their customizations. However, because the controlling logic for these client-side programs is not located onForce.com platform servers, they are restricted by:
- The performance costs of making multiple round-trips to theSalesforce site to accomplish common business transactions
- The cost and complexity of hosting server code, such as Java or .NET, in a secure and robust environment
To address these issues, and to revolutionize the way that developers create on-demand applications, Salesforce introducesForce.com Apexcode, the first multitenant, on-demand programming language for developers interested in building the next generation of business applications.
- What is Apex?—more about when to use Apex, the development process, and some limitations
- What’s new in this Apex release?
- Apex Quick Start—delve straight into the code and write your firstApex class and trigger
What is Apex?
Available in: Salesforce Classic and Lightning Experience |
Available in: Enterprise, Performance, Unlimited, Developer, andDatabase.com Editions |
User Permissions Needed | |
---|---|
To define, edit, delete, set security, set version settings, show dependencies, and run tests for Apex classes: | “AuthorApex” |
To define, edit, delete, set version settings, and show dependencies for Apex triggers: | “AuthorApex” |
Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Force.com platform server in conjunction with calls to theForce.com API. Using syntax that looks like Java and acts like database stored procedures, Apex enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages. Apex code can be initiated by Web service requests and from triggers on objects.
You can add Apex to most system events.

As a language, Apex is:
- Integrated
- Apex provides built-in support for common Force.com platform idioms, including:
- Data manipulation language (DML) calls, such as INSERT, UPDATE, and DELETE, that include built-in DmlExceptionhandling
- Inline Salesforce Object Query Language (SOQL) and SalesforceObject Search Language (SOSL) queries that return lists of sObject records
- Looping that allows for bulk processing of multiple records at a time
- Locking syntax that prevents record update conflicts
- Custom public Force.com API calls that can be built from storedApex methods
- Warnings and errors issued when a user tries to edit or delete a custom object or field that is referenced by Apex
- Easy to use
- Apex is based on familiar Java idioms, such as variable and expression syntax, block and conditional statement syntax, loop syntax, object and array notation, and so on. Where Apex introduces new elements, it uses syntax and semantics that are easy to understand and encourage efficient use of the Force.com platform. Consequently,Apex produces code that is both succinct and easy to write.
- Data focused
- Apex is designed to thread together multiple query and DML statements into a single unit of work on the Force.com platform server, much as developers use database stored procedures to thread together multiple transaction statements on a database server. Note that like other database stored procedures, Apex does not attempt to provide general support for rendering elements in the user interface.
- Rigorous
- Apex is a strongly-typed language that uses direct references to schema objects such as object and field names. It fails quickly at compile time if any references are invalid, and stores all custom field, object, and class dependencies in metadata to ensure they are not deleted while required by active Apex code.
- Hosted
- Apex is interpreted, executed, and controlled entirely by theForce.com platform.
- Multitenant aware
- Like the rest of the Force.com platform, Apex runs in a multitenant environment. Consequently, the Apex runtime engine is designed to guard closely against runaway code, preventing it from monopolizing shared resources. Any code that violates limits fails with easy-to-understand error messages.
- Automatically upgradeable
- Apex never needs to be rewritten when other parts of the Force.complatform are upgraded. Because compiled code is stored as metadata in the platform, Apex is upgraded as part of Salesforce releases.
- Easy to test
- Apex provides built-in support for unit test creation and execution, including test results that indicate how much code is covered, and which parts of your code could be more efficient. Salesforce ensures that all custom Apex code works as expected by executing all unit tests prior to any platform upgrades.
- Versioned
- You can save your Apex code against different versions of theForce.com API. This enables you to maintain behavior.
Apex is included in Performance Edition, Unlimited Edition, Developer Edition, Enterprise Edition, and Database.com.
When Should I Use Apex?
The Salesforce prebuilt applications provide powerful CRM functionality. In addition, Salesforce provides the ability to customize the prebuilt applications to fit your organization. However, your organization may have complex business processes that are unsupported by the existing functionality. When this is the case, theForce.com platform includes a number of ways for advanced administrators and developers to implement custom functionality.These include Apex, Visualforce, and the SOAP API.
Use Apex if you want to:
- Create Web services.
- Create email services.
- Perform complex validation over multiple objects.
- Create complex business processes that are not supported by workflow.
- Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object).
- Attach custom logic to another operation, such as saving a record, so that it occurs whenever the operation is executed, regardless of whether it originates in the user interface, a Visualforce page, or from SOAP API.
Visualforce consists of a tag-based markup language that gives developers a more powerful way of building applications and customizing the Salesforce user interface. With Visualforce you can:
- Build wizards and other multistep processes.
- Create your own custom flow control through an application.
- Define navigation patterns and data-specific rules for optimal, efficient application interaction.
For more information, see the Visualforce Developer’s Guide.
Use standard SOAP API calls if you want to add functionality to a composite application that processes only one type of record at a time and does not require any transactional control (such as setting a Savepoint or rolling back changes).
For more information, see the SOAP API Developer’s Guide.
No comments:
Post a Comment