SlideShare a Scribd company logo
1 of 30
1Dr. Preethi Harris
Agenda
 Introduction
 Declarative approach
 Programmatic approach
 Apex Basics
 SOQL/SOSL
 DML
 Apex Triggers
 References
2BDCC 2018
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
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
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
6
Object Relationships
Lookup
Master
detail
Self
Hierarc
hy
Extern
al &
indirect
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
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
 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
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.
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
 Branching – if else
 Looping – for, do while, while
Control Structures:
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.
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[]
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]
 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.
 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) { }
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 }
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 }
 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.
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 }
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
 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 }
BDCC 2018 30

More Related Content

What's hot (18)

Session06 handling xml data
Session06  handling xml dataSession06  handling xml data
Session06 handling xml data
 
Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivity
 
Ch 7 data binding
Ch 7 data bindingCh 7 data binding
Ch 7 data binding
 
Ado object
Ado objectAdo object
Ado object
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Accessing data with android cursors
Accessing data with android cursorsAccessing data with android cursors
Accessing data with android cursors
 
ADO.NET by ASP.NET Development Company in india
ADO.NET by ASP.NET  Development Company in indiaADO.NET by ASP.NET  Development Company in india
ADO.NET by ASP.NET Development Company in india
 
JPA 2.0
JPA 2.0JPA 2.0
JPA 2.0
 
Android - Saving data
Android - Saving dataAndroid - Saving data
Android - Saving data
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
Salesforce meetup | Custom document generation
Salesforce meetup | Custom document generationSalesforce meetup | Custom document generation
Salesforce meetup | Custom document generation
 
Oraclesql
OraclesqlOraclesql
Oraclesql
 
ch4
ch4ch4
ch4
 
ShmooCon 2009 - (Re)Playing(Blind)Sql
ShmooCon 2009 - (Re)Playing(Blind)SqlShmooCon 2009 - (Re)Playing(Blind)Sql
ShmooCon 2009 - (Re)Playing(Blind)Sql
 
Tk2323 lecture 9 api json
Tk2323 lecture 9   api jsonTk2323 lecture 9   api json
Tk2323 lecture 9 api json
 
Android sq lite-chapter 22
Android sq lite-chapter 22Android sq lite-chapter 22
Android sq lite-chapter 22
 
Ddl
DdlDdl
Ddl
 
e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plus
 

Similar to Preethi apex-basics-jan19

Introduction to apex
Introduction to apexIntroduction to apex
Introduction to apexRinku Saini
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIRPeter Elst
 
Using object dependencies in sql server 2008 tech republic
Using object dependencies in sql server 2008   tech republicUsing object dependencies in sql server 2008   tech republic
Using object dependencies in sql server 2008 tech republicKaing Menglieng
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsSalesforce Developers
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Servicesukdpe
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex codeEdwinOstos
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoHasnain Iqbal
 
Summer '16 Realease notes
Summer '16 Realease notesSummer '16 Realease notes
Summer '16 Realease notesaggopal1011
 
Database Foundation Training
Database Foundation TrainingDatabase Foundation Training
Database Foundation TrainingFranky Lao
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesKeshav Murthy
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq lsInSync Conference
 
Programming Building Blocks for Admins
Programming Building Blocks for Admins Programming Building Blocks for Admins
Programming Building Blocks for Admins Salesforce Admins
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And XmlDavid Truxall
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 

Similar to Preethi apex-basics-jan19 (20)

Introduction to apex
Introduction to apexIntroduction to apex
Introduction to apex
 
SQLite in Adobe AIR
SQLite in Adobe AIRSQLite in Adobe AIR
SQLite in Adobe AIR
 
Using object dependencies in sql server 2008 tech republic
Using object dependencies in sql server 2008   tech republicUsing object dependencies in sql server 2008   tech republic
Using object dependencies in sql server 2008 tech republic
 
Apex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong FoundationsApex Enterprise Patterns: Building Strong Foundations
Apex Enterprise Patterns: Building Strong Foundations
 
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu   (obscure) tools of the trade for tuning oracle sq lsTony Jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Sql
SqlSql
Sql
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex code
 
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael PizzoADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
ADO.NET Entity Framework by Jose A. Blakeley and Michael Pizzo
 
Summer '16 Realease notes
Summer '16 Realease notesSummer '16 Realease notes
Summer '16 Realease notes
 
Unit 3
Unit 3Unit 3
Unit 3
 
Database Foundation Training
Database Foundation TrainingDatabase Foundation Training
Database Foundation Training
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql Features
 
SetFocus Portfolio
SetFocus PortfolioSetFocus Portfolio
SetFocus Portfolio
 
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Tony jambu   (obscure) tools of the trade for tuning oracle sq lsTony jambu   (obscure) tools of the trade for tuning oracle sq ls
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
 
Programming Building Blocks for Admins
Programming Building Blocks for Admins Programming Building Blocks for Admins
Programming Building Blocks for Admins
 
Sql Summit Clr, Service Broker And Xml
Sql Summit   Clr, Service Broker And XmlSql Summit   Clr, Service Broker And Xml
Sql Summit Clr, Service Broker And Xml
 
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Preethi apex-basics-jan19

  • 2. Agenda  Introduction  Declarative approach  Programmatic approach  Apex Basics  SOQL/SOSL  DML  Apex Triggers  References 2BDCC 2018
  • 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 }

Editor's Notes

  1. SaaS-Hotel PaaS-Rented house IaaS-Own property Heruku-Use cloud connector for cross cloud/platform integration, Legacy system
  2. Objects - Tables
  3. 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.
  4. Apex is case-insenstive
  5. Debug-> Open execute anonymous window Type invocation method, ensure open log is selected Debug only
  6. MyExternalID custom field