Wednesday, 25 January 2012

Apex Introduction

Apex is a strongly-typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the platform server in conjunction with calls to the​ 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:
Apex provides built-in support for common 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 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
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, and so on. Where Apex introduces new elements, it uses syntax and semantics that are easy to understand and encourage efficient use of the 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 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.
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.
Apex is interpreted, executed, and controlled entirely by the platform.
Multitenant aware
Like the rest of the platform, Apex runs in a multitenant environment. Consequently, the Apex runtime engine is designed to guard closely against runaway code, preventing them from monopolizing shared resources. Any code that violate these limits fail with easy-to-understand error messages.
Automatically upgradeable
Apex never needs to be rewritten when other parts of the platform are upgraded. Because the compiled code is stored as metadata in the platform, it always gets automatically upgraded with the rest of the system.
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. ensures that Apex code always work as expected by executing all unit tests stored in metadata prior to any platform upgrades.
You can save your Apex code against different versions of the API. This enables you to maintain behavior.
Apex is included in Unlimited Edition, Developer Edition, Enterprise Edition, and
Data Types:
1.Primitive Data Types
2.sObject Types

In Apex, all variables and expressions have a data type that is one of the following:
  • A primitive, such as an Integer, Double, Long, Date, Datetime, String, ID, or Boolean (see Primitive Data Types)
  • An sObject, either as a generic sObject or as a specific sObject, such as an Account, Contact, or MyCustomObject__c (see sObject Types)
  • A collection, including:
    • A list (or array) of primitives, sObjects, user defined objects, objects created from Apex classes, or collections (see Lists)
    • A set of primitives (see Sets)
    • A map from a primitive to a primitive, sObject, or collection (see Maps)
  • A typed list of values, also known as an enum (see Enums)
  • Objects created from user-defined Apex classes (see Classes, Objects, and Interfaces)
  • Objects created from system supplied Apex classes (see Apex Classes)
  • Null (for the null constant, which can be assigned to any variable)
Methods can return values of any of the listed types, or return no value and be of type Void.
Type checking is strictly enforced at compile time. For example, the parser generates an error if an object field of type Integer is assigned a value of type String. However, all compile-time exceptions are returned as specific fault codes, with the line number and column of the error. For more information, see Debugging Apex.

Primitive Data Types

No comments:

Post a Comment

Getting Reference FieldsI(Lookup or Master detail) through dynamic apex

Hi , We  had a scenario If  we get a parameter "id" in the  url  then we should  be  able to find out    object reference is ...