3. Introduction
Cloud services – B2B
SaaS – Any login via URL with credentials
PaaS – Force.com, Heroku (Cross platform & legacy
systems)
App development – Web App, Mobile App
App – UI + BL + automation
Framework
Model View Controller (MVC)
Java
Aura
80/20 rule
• Governor limits – Developer Org, Enterprise license
3
4. Data organization:
App
User Interface (UI) + Business Logic (BL) + automation
Org
Instance of Salesforce
Place for data, configuration
and customization
log in to access
Object
Field Record
Declarative Approach
5. Building data model declaratively:
5
Standard
object
• predefined,
• Cannot
delete
• Not
customizable
Custom object
• User defined,
• can be
deleted
• customizable
Objects – Tables
Standard object – cannot be child
Custom object – Parent/child
7. 7
Workflow
• One condition at a
time(Single if/then logic)
• 4 actions
• Does not support a
visual designer
• Creates records for
tasks
• Recursion for field
updates only
• Reusability-actions
Process Builder
• More than one condition
(multiple if/then logic)
• 9 actions
• Supports a visual
designer
• Creates records for
objects
• Supports recursion (5
times)
• Reusability-Entire
process
8. Programmatic Approach
8
Declarative
• UI (View)
• Apps, lightening tabs,
page layout
• BI (Controller)
• Validation rules, Process
builder/Flow, Workflow,
Approval process, Quick
actions
• Data model (Model)
• Objects
• Fields
• Relationships
Programmatic
• UI (View)
• Visual Force page,
Lightening components
• BI (Controller)
• Apex classes
• Data model (Model)
• Meta data
• API
9. Apex is a programming language that uses Java-like syntax
and acts like database stored procedures
Apex enables developers to add business logic to system
events, such as button clicks, updates of related records,
and Visualforce pages
Features:
Hosted
Object oriented & Strongly typed
Multitenant aware
Integrated with the database
Data focused
Easy to use
Easy to test
Versioned
Apex Basics
10. Significance:
Cloud development as Apex is stored, compiled,
and executed in the cloud.
Triggers, which are similar to triggers in database
systems.
Database statements that allow you to make
direct database calls and query languages to
query and search data.
Transactions and rollbacks.
The global access modifier, which is more
permissive than the public modifier and allows
access across namespaces and applications.
Versioning of custom code.
11. Datatypes:
A primitive, such as an Integer, Double,
Long, Date, Datetime, String, ID,
Boolean, among others.
sObject, either as a generic sObject or
as a specific sObject, such as an
Account, Contact, or
MyCustomObject__c
Collection:
◦ Lists (Arrays)
◦ Sets
◦ Maps
12. Branching – if else
Looping – for, do while, while
Control Structures:
13.
14.
15.
16.
17.
18.
19. SOQL/SOSL
Sobject:
Each Salesforce record is represented as
an sObject before it is inserted into Salesforce
When persisted records are retrieved from Salesforce,
they're stored in an
sObject variable
SOQL and SOSL statements in Apex can reference
Apex code variables and expressions if they’re
preceded by a colon (:).
This use of a local code variable within a SOQL or
SOSL statement is called a bind.
The Apex parser first evaluates the local variable in
code context before executing the SOQL or SOSL
statement.
20. DML Statements
Insert Statement
The insert DML operation adds one or more sObjects & is
analogous to the INSERT statement in SQL.
Syntax
insert sObject
insert sObject[]
Account newAcct = new Account(name = 'Acme');
try { insert newAcct;
} catch (DmlException e) {
// Process exception here }
Update Statement
The update DML operation modifies one or more existing sObject
records, & is analogous to the UPDATE statement in SQL.
Syntax
update sObject
update sObject[]
21. Account a = new Account(Name='Acme2'); insert(a);
Account myAcct = [SELECT Id, Name, BillingCity FROM
Account WHERE Id = :a.Id]; myAcct.BillingCity = 'San
Francisco';
try {
update myAcct;
} catch (DmlException e) {
// Process exception here }
Upsert Statement
The upsert DML operation creates new records and updates
sObject records within a single statement, using a specified
field to determine the presence of existing objects, or the ID
field if no field is specified.
Syntax
upsert sObject [opt_field]upsert sObject[] [opt_field]
22. The upsert statement matches the sObjects with existing
records by comparing values of one field.
If field is not specified when calling this statement,
the upsert statement uses the sObject’s ID to match the
sObject with existing records in Salesforce.
For custom objects, specify a custom field marked as external
ID. For standard objects, you can specify any field that has
the idLookup attribute set to true.
upsert sObjectList Account.Fields.MyExternalId__c;
How Upsert Chooses to Insert or Update
Upsert uses the sObject record's primary key (the ID), an
idLookup field, or an external ID field to determine whether it
should create a new record or update an existing one:
If the key is not matched, a new object record is created.
If the key is matched once, the existing object record is
updated.
If the key is matched multiple times, an error is generated and
the object record is neither inserted or updated.
23. Upsert a list of accounts
List<Account> acctList = new List<Account>();
// Fill the accounts list with some accounts
try {
upsert acctList;
} catch (DmlException e) { }
Upsert list of accounts using a foreign key for matching existing
records
List<Account> acctList = new List<Account>();
// Fill the accounts list with some accounts
try {
// Upsert using an external ID field
upsert acctList myExtIDField__c;
} catch (DmlException e) { }
24. Delete Statement
The delete DML operation deletes one or
more existing sObject records
delete is analogous to the delete() statement in the
SOAP API.
Syntax
delete sObject
delete sObject[]
delete all accounts that are named 'DotCom
Account[] doomedAccts = [SELECT Id, Name FROM
Account WHERE Name = 'DotCom'];
try {
delete doomedAccts;
} catch (DmlException e)
{ // Process exception here }
25. Undelete Statement
The undelete DML operation restores one or more
existing sObject records, undelete is analogous to
the UNDELETE statement in SQL.
Syntax
undelete sObject | IDundelete sObject[] | ID[]
This example undeletes an account named
'Universal Containers’. The ALL ROWS keyword
queries all rows for both top level and aggregate
relationships, including deleted records and
archived activities.
Account[] savedAccts = [SELECT Id, Name FROM
Account WHERE Name = 'Universal Containers'
ALL ROWS];
try {
undelete savedAccts;
} catch (DmlException e)
{ // Process exception here }
26. Merge Statement
The merge statement merges up to three records of the
same sObject type into one of the records, deleting the
others, and re-parenting any related records.
Syntax
merge sObject sObjectmerge sObject sObject[]
merge sObject ID
merge sObject ID[]
The first parameter represents the master record into
which the other records are to be merged. The second
parameter represents the one or two other records that
should be merged and then deleted. You can pass these
other records into the merge statement as a single
sObject record or ID, or as a list of two sObject records
or IDs.
27. List<Account> ls = new List<Account>{new
Account(name='Acme Inc.'),new
Account(name='Acme')};
insert ls;
Account masterAcct = [SELECT Id, Name FROM
Account WHERE Name = 'Acme Inc.' LIMIT 1];
Account mergeAcct = [SELECT Id, Name FROM
Account WHERE Name = 'Acme' LIMIT 1];
try {
merge masterAcct mergeAcct;
} catch (DmlException e)
{ // Process exception here }
28. Triggers
Apex can be invoked by using triggers .
Apex triggers enable you to perform custom
actions before or after changes to Salesforce
records, such as insertions, updates, or deletions.
A trigger is Apex code that executes before or after
the following types of operations:
Insert
update
delete
merge
upsert
undelete
29. There are two types of triggers:Before triggers are
used to update or validate record values before
they’re saved to the database.
After triggers are used to access field values that
are set by the system (such as a
record's Id or LastModifiedDate field), and to affect
changes in other records, such as logging into an
audit table or firing asynchronous events with a
queue. The records that fire the after trigger are
read-only.
Syntax:
trigger <TriggerName> on <ObjectName>
(trigger_events) { code_block }
trigger myAccountTrigger on Account (before insert,
before update) { // Your code here }
SaaS-Hotel
PaaS-Rented house
IaaS-Own property
Heruku-Use cloud connector for cross cloud/platform integration, Legacy system
Objects - Tables
Hosted—Apex is saved, compiled, and executed on the server—the Lightning Platform.
Object oriented—Apex supports classes, interfaces, and inheritance.
Strongly typed—Apex validates references to objects at compile time.
Multitenant aware—enforcing governer limits, which prevent code from monopolizing shared resources.
Integrated with the database—It is straightforward to access and manipulate records.
Data focused—Apex provides transactional access to the database, allowing you to roll back operations.
Easy to use—Apex is based on familiar Java idioms.
Easy to test—Apex provides built-in support for unit test creation, execution, and code coverage. Salesforce ensures that all custom Apex code works as expected by executing all unit tests prior to any platform upgrades.
Versioned—Custom Apex code can be saved against different versions of the API.
Apex is case-insenstive
Debug-> Open execute anonymous window
Type invocation method, ensure open log is selected
Debug only