Posted in APEX

Salesforce : What is Apex ?

APEX in Salesforce

images (2)

apexLogo images (3)

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.

 my

Apex provides built-in support for common Force.com platform idioms, including:

1. Data manipulation language (DML)

  • Insert
  • Update
  • Delete
  1. Soql and Sosl (To return records and search records)
  2. Looping that allows for bulk processing of multiple records at a time
  3.  Custom public Force.com API calls that can be built from stored Apex methods

Apex is:

imagest

  • Easy to use
  • Data focused
  • Hosted
  • Multi-tenant aware
  • Easy to test
  • Version-ed

How Does Apex Work?

 n

 

Where to write Apex?

 images (6) images (4)

  • The com IDE is a plug-in for the Eclipse IDE
  • For a trigger on a standard object, from Setup, click Customize, click the name of the object, and click Triggers. In the Triggers detail page, click New and then enter your code in the Body text box.
  • For a trigger on a custom object, from Setup, click Develop Objects, and click the name of the object. In the Triggers related list, click New, and then enter your code in the Body text box.
  • For a class, from Setup, click Develop Apex Classes. Click New, and then enter your code in the Body text box.

Note: You cannot make changes to Apex using the Salesforce user interface in a Salesforce production organization.

images (5)

When Should I Use Apex?

  • Create Web services.
  • Create email services.
  • Perform complex validation over multiple objects.
  • Create complex business processes that are not supported by workflow

Language Constructs:

The following language constructs form the base parts of Apex:

  • Data Types
  • Variables
  • Expressions
  • Assignment Statements
  • Conditional (If-Else) Statements
  • Loops
  • SOQL and SOSL Queries
  • Exception Statements

 

DataType:

Primitive Data Types:

  • Apex primitive datatypes include:
    • Boolean
    • Date
      Datetime
      Decimal
      Double
      iD
      Integer
      Long
      String
      Time

Apex uses the same primitive data types as the SOAP API. All primitive data types are passed by value

Variables:

Local variables are declared with Java-style syntax. For example:

Integeri=0;

String str;

Account a;

  • Note: Multiple Variable can initialized in a single statement  Integer i,j,k;

Case Sensitivity:

Apex is Case In Sensitive.

  • Variable and method names are case insensitive.
  • References to object and field names are case insensitive.
  • SOQL and SOSL statements are case insensitive.

Example:

Account[] accts = [Select ID From Account where Name=’salesforce’]

images (1)

Exception Statements:

Apex uses  exceptions to note errors and other events that disrupt the normal flow of code execution. Throw statements can be used to generate exceptions, while  try, catch , and  finally can be used to gracefully recover from an exception.

Try

{

Code block ;//Dml Insert

}

Catch(exception){

Code block;//Dml Exception

}

images5

Advertisements

Author:

Hi! I am Pritam Shekhawat, Salesforce MVP. I am working as a 3x Certified Salesforce developer as well I am a co-leader of Noida Salesforce user group. Most important thing which I like about Salesforce is giving back. There aren’t enough words in the dictionary to describe the significance of giving back.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s