Apex Code: The World's First On-Demand Programming Language
Apex Code: The World's First On-Demand Programming Language
Apex Code: The World's First On-Demand Programming Language
WHIT EPAPER
Contents
Extending the Power of the Apex Platform ....................................................................................... 1
Apex Cod e: T he Wor ld ’s F irst On-D ema nd Pro gram m ing La n gua ge 1
WHIT EPAPER
In this example, one can see some key concepts at work: the Java-like syntax of the variable declaration and
if statement, the use of SOQL to retrieve data just as one would with the Web service API, and the use of the
trigger declaration to define the trigger’s scope, that is, what events it acts upon.
Apex Cod e: T he Wor ld ’s F irst On-D ema nd Pro gram m ing La n gua ge 2
Apex Code and event model. Apex Code can be tied to the execution of the platform, enabling developers to
exert fine-grain control over an application. When thinking about the Apex code, it’s useful to consider the
analogy of stored procedures and triggers, since the language is fundamentally tied to behaviors on the data,
as opposed to providing a higher level UI language or representation. Hence developers can tie Apex Code
into almost every aspect of an application’s behavior: overriding the behavior in existing buttons, creating a
new button, manipulating the control of a custom link, programming the control of an inline S-control, or
even overriding the behaviors associated with a related list and data.
Consider an app that enables the user to create a new lead in Salesforce by clicking the save button to commit
that record to the database. With Apex code, developers can create and execute code residing on
salesforce.com’s server to intercede just after the button is clicked. The code might check for any duplicate
records, and if it finds any, implement a data quality scenario that notifies the user. Otherwise, the record
commits to the database as is normally the case. (See Apex Code Example above.)
Transaction control. Because Apex Code is closely bound to Salesforce data, developers can readily add
transactional features to their applications. For example, if one user is referencing a field while somebody
else is trying to delete it, the system is aware of the conflict. Apex Code also features data commits and
rollbacks, which are especially important when working across multiple objects.
Packaging, re-use and Web services. Apex Code uses a packaging model similar to that of Java, in which
reusable packages of code can be invoked from each other or from within triggers. Unlike Java, however,
Apex is not object-oriented in the sense that those packages can be modified through inheritance.
Significantly, any method defined in a package can optionally be automatically exposed as a Web service,
and thus can be invoked via the Web service API or directly through the AJAX toolkit.
Performance, scalability and upgrades. Because Apex Code runs on demand, scalability, compatibility,
and maintenance issues are salesforce.com’s responsibility, not yours. Apex-developed applications can
scale indefinitely to support additional users, without your having to deploy additional servers. Applications
potentially run faster because a single query can obtain information from multiple objects.
When newer versions of Salesforce and the Apex code itself are introduced, your code is never rendered
obsolete. Salesforce.com ensures backward compatibility by maintaining processor-specific versions of Apex
virtual machines, which in turn correspond to the API. As a result, your code continues to operate without
modification.
Apex Code and the AppExchange. Apex Code can be packaged alongside custom objects, S-controls and
other platform features, allowing developers to redistribute their Apex Code-enhanced apps via the same
AppExchange directory available today.
3
WP – Apex Code – 01/07