APEX basic concept

Posted on Updated on

Apex ?

It is a Strongly typed Object-oriented programming language. It allows developers to execute flow and transaction control statements on the Force.com platform server in conjunction with calls to the Force.com​ API. Its Syntax looks like the Java and Database stored procedures.


  • Apex enables developers to add business logic to most system events including button clicks, related record updates, and Visualforce pages.
  • Apex allows developers to attach the business logic to the record save process.
  • It supports for unit test creation and execution.
  • Apex code can be initiated by Web service requests and from triggers on objects.
  • Apex is Integrated, Easy to use, Multitenant aware, automatically upgradable, easy to test, Hosted and Versioned.

Apex Architecture

Apex is compiled, stored, and run entirely on the Force.com platform


When a developer writes and saves Apex code to the platform, the platform application server first compiles the code and saves in the form of metadata.

End users can send the request from the Visualforce pages(UI) and retrieve results from the salesforce servers.

Capabilities of Apex

  • Apex provided build in support for:
  • DML calls to insert, update and delete records.
  • Inline SOQL or SOSL statements for retrieving records.
  • Looping control structures that help with bulk processing.
  • A record locking syntax that prevents record update conflicts.
  • Custom public API calls.
  • Send and receive Emails.
  • Web services or XML request/response integrations.
  • Warning and Errors to prevent objects referenced by Apex from being notified.

7 Reasons to Choose APEX Programming Language for Your Next Salesforce based Application.

1   Quick access to Salesforce’s existing thousands of company’s users base and Salesforce Apps.

2   Ride on Salesforce’s cutting-edge existing functionality, including:

  • Administrative interface
  • User management and authentication
  • Reporting and analytics
  • Dynamic API
  • Toolkits and integrations for other languages and platforms

3   No worries about server maintenance or architecture as this is a PaaS platform

4   Security, both because of code review and because of high degree of control on the platform

5    Speed to learn the language as this is Java-like syntax, based on familiar Java idioms, such as variable and expression syntax, block and conditional statement syntax, loop syntax, object and array notation and much more, that speeds up the learning curve for new developers.

6    Native “Visualforce” elements allow fast and smooth information output

7    Connecting with one of the most active software development communities across the planet. Vast knowledge base with active participation from Salesforce staff.

What is Apex class and Triggers?

Apex class

It is a collection of variables and library of methods that can reused.

To define a class, specify the following:

  1. Access modifiers:
    • You must use one of the access modifiers (such as public or global) in the declaration of a top-level class.
    • You do not have to use an access modifier in the declaration of an inner class.
  2. Optional definition modifiers (such as virtual, abstract, and so on)
  3. Required: The keyword class followed by the name of the


private | public | global

[virtual | abstract | with sharing | without sharing]

class*** ClassName*** [implements InterfaceNameList] [extends ClassName]


// The body of the class


Apex Triggers

A trigger is Apex code that executes before or after the following types of operations:

  • insert
  • update
  • delete
  • merge
  • upsert
  • undelete

For example, you can have a trigger run before an object’s records are inserted into the database, after records have been deleted, or even after a record is restored from the Recycle Bin.


trigger ***TriggerName*** on ObjectName (trigger_events) {   code_block}