2. When Developer writes and save code in platform , Which is
compiled on force.com platform and store in the form of
metadata in the salesforce server. End users can send request
from UI and retrieve result from salesforce server.
Working of Apex-
4. Introducing Apex
Force.com allows many customizations through User
Interface
Force.com API allows developers to write client-side
programs or integrations for more flexibility in their
applications
Client side programs have performance costs
Lack transactional control across API requests
Cost and complexity of client hosting server code
APEX was introduced to address those issues and to
revolutionize the way developers create on-demand
applications.
5. Apex Code Is
Strongly-typed, object-based programming language
Enables developers to execute logic and transaction
control statements on Force.com
Runs natively on the server
Code executes on the server when initiated by User
Interface via Buttons & Events, and data through the
API
Java or C#-like syntax
Transactional
6. How is Apex Different?
Executes directly on the Force.com
Eliminates network traffic between client application and
Force.com
Apex Code tightly integrated to the rest of the platform
functionality
Changes to the metadata referenced in Apex Code will
cause an automatic recompilation the next time those
components are executed
7. Language Basics
Data Types – Primitive
- String
- Boolean
- Date and DateTime
- Integer, Long, Double
- ID (Force.com database record identifier)
- Blob (for storing binary data)
- Sobject (object representing a Force.com standard or custom
object)
Example:
DateTime dt = System.now() + 1;
Boolean isClosed = true;
String sCapsFirstName = ‘Andrew’.toUpperCase();
Account acct = new Account(); //Sobject example
8. Language Basics (cont)
Data Types – Collections
Lists - A list can contain duplicate elements.
Sets - A Set is a Collection that cannot contain duplicate elements
Maps – A Map is a pair of key and value.
Arrays - fixed-size sequential collection of elements of the same
type.
Example:
List<Integer> myList = new List<Integer>();
myList.add(12); //Add the number 12 to the list
myList.get(0); //Access to first integer stored in the List
9. Force.com Query Languages
SOQL – Salesforce object Query Language
String myName = ‘Acme’;
Account[] accts = [SELECT ID FROM Account WHERE name =:myName] //Pass in a variable
SOSL – Salesforce object Search Language
List<List<SObject>> searchList = [FIND '415' IN PHONE FIELDS RETURNING Account, Contact ];
Account [] accounts = ((List<Account>)searchList[0]);
Contact [] contacts = ((List<Contact>)searchList[1]);
10. Data Manipulation with Apex
DML (Data Manipulation Language)
- Insert
- Update
- Upsert - Operation to create a new or update existing record
based on an external id.
- Delete
- Undelete
11. Apex Triggers-
Syntex of writing trigger-
trigger TriggerName on ObjectName (trigger_events) {
code_block
}
Rules to write trigger-
It starts with the keyword trigger.
A unique trigger name to differentiate it from the other triggers.
Multiple trigger can be defined on the same database object.
You must name the database object on which to create the trigger.
You can create trigger on custom and standard objects.
A comma separated list of one or more trigger events that cause the trigger code to be
executed.
A event is specified using two keywords 1st one is either before or after. These
indicate that the trigger is going to be executed before or after the database operation
is saved.
The 2nd keyword is the DML operation - insert, update, delete or undelete.
12. Apex Class-
Defination- Class is the collection of data member and
member method.
Syntex of Class-
Public class CustomClass{
Public CustomClass(){} //constructor
}
Access Specifiers-
Private
Protected
Public
global
13. Difference between Class And Triggers
Class-
An Apex class is a template or blueprint from which Apex objects
are created.
Classes consist of other classes, user-defined methods, variables,
exception types.
Triggers-
A trigger is Apex code that executes before or after specific data
manipulation language (DML) events occur, such as before object
records are inserted into the database, or after records have been
deleted.
A trigger is associated with a standard or custom object and can call
methods of Apex classes
15. MVC Meaning-
Model - includes the custom and standard objects.
View - is defined by VF pages.
Visualforce Page - are the salesforce created pages. That is
a markup language.
Controller - includes the standard,custom, extension
classes.
That are also known as - Standard controller, custom
controller and extension controller.