What is Apex?
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 the Force.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.
Apex vs. Java
They are both similar in syntax and notation, strongly typed and transactional. Both support OOP features viz. Encapsulation, Inheritance, Polymorphism.
Apex runs in a Multi-Tenanted environment and is limited by Governor limits. It is case-sensitive and compiled on-demand. It is a Force.com platform proprietary language used specifically for business functions and requires unit testing for deployment.
Apex Class vs. Apex Triggers
An Apex Class is a library of attributes and methods and serves as a blueprint to create Apex objects. An Apex Class is similar to a Java Class and it can implement multiple interfaces.
An Apex Trigger is a script that executes before a specific event. An Apex Trigger can be associated with both a Standard Object and a Custom Object and executes as soon as an Object is saved.
Apex is invoked in one of the following ways:
- Triggers are executed when data is saved through the UI or the API
- By creating a job through the Apex Scheduler
- Through VF controllers which provide data and actions to VF pages
- Through Web Services API for classes exposed as Web Services
- Through anonymous code blocks which are used for testing and debugging
When do you use Apex Triggers?
- When you want to execute logic and perform some action when a record is deleted because validation rules only execute when a record is created or edited
- Reuse existing interfaces by querying external Data Source(s) via web services and verify that business rules are being met. The Apex Trigger can then update the Data Source to keep the systems in sync
- When you want to create a custom web service that wraps updates to multiple objects in a transaction or executes complex business logic
- To get around limitations of Workflow Rules by automating field updated to unrelated records
- To automate the creation or the deletion of a new record
- To execute complex actions that write to multiple objects when a button or a link is clicked
- To identify duplicate records and merge the results or to move existing records to a new object
- To create a custom email service to handle inbound emails
As a language, Apex is:
[message_box title=”Salesforce.com Certified” color=”blue”]From the small business to the large enterprise, we have solutions to help improve win rates.[/message_box]
Contact Us