Вы находитесь на странице: 1из 18

Apex

Topics
What is Apex? Why Apex? Framework When Apex? Example Governor Limits Dos and Donts

What is Apex?
Apex is an 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. Apex is interpreted, executed, and controlled entirely by the Force.com platform. Apex allows developers to add business logic to most system events, including button clicks, related record updates and many more. Apex is based on familiar Java idioms, such as variable and expression syntax, block and conditional statement syntax, loop syntax, object and array notation, pass by reference, etc. Apex provides built-in support for unit test creation and execution.

Features
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 DmlException handling Inline Salesforce Object Query Language (SOQL) and Salesforce Object 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 stored Apex 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 Rigorous Hosted Automatically upgradeable Easy to test Version

Why Apex?
Performance cost of making multiple round trip to accomplish common business transaction. Efficient Transactional control. Record locking to avoid concurrency and dead lock. Complied at Force.com platform, no processing at client browser to improve performance. Compiled apex code talks with meta data instead of database. Metadata also stores information about relations and dependencies between records. Extends salesforce functionality beyond standard functions and in the way you want.

Apex Framework

When to use Apex?


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 the Web Services API

Invoking Apex
Triggers on standard and custom objects. Apex classes which can be invoked from triggers, scontrols, web service API and other classes.

Tools
Salesforce.com User Interface. Eclipse IDE with Force.com plug-in.

Example

Limitations
Cannot create temporary files Change standard functionalityApex can only prevent the functionality from happening, or add additional functionality

Dos and Donts


Dos:
Always write the business logic in the class and call it from triggers. In test methods, always create dummy records. (motive should be testing the business requirement rather than covering the lines of code)

Donts:
Avoid splitting your business logic in triggers and classes because it would be very difficult to understand the business logic if the code is scattered. Use existing Production DB records in test methods, only if it is required.

Governor Limits

Deployment
Ensure
Apex test methods to check logical flow of code. Code coverage of Apex class/trigger should be above 75%. Two ways to deploy 1. Via SF Deployment changeset 2. Force.com IDE

Basics of Apex
Datatypes Collection methods Conditional Statements Loops Exception Handling

Datatypes
Primitive Blob Boolean Date Datetime Decimal Double ID Integer Long String Time sObject: Any object which is available in the SF DB Collection
List Maps Sets

List Its an ordered collection of primitives, sObjects Set Its an unordered collection of primitives, sObjects that do not contain any duplicate elements. Maps Its a collection of key-value pairs where each unique key maps to a single value

Thanks!!!

Вам также может понравиться