SlideShare a Scribd company logo
Introduction to Apex
for Programmers
March 27, 2014
#forcewebinar
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of
the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking
statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service
availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future
operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use
of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our
service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth,
interruptions or delays in our Web hosting, breach of our security measures, the outcome of intellectual property and other litigation, risks associated with
possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and
motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-
salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial
results of salesforce.com, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended July 31, 2012. This documents and
others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be
delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available.
Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
#forcewebinar
Speakers
Joshua
Birk
Developer Evangelist
@joshbirk
LeeAnne
Templeman
Developer Evangelist
@leeanndroid
#forcewebinar
Follow Developer Force for the Latest News
@forcedotcom / #forcewebinar
Developer Force – Force.com Community
Developer Force
Developer Force Group
+Developer Force – Force.com Community
#forcewebinar
Have Questions?
§  We have an expert support team at the ready to answer your questions
during the webinar.
§  Ask your questions via the GoToWebinar Questions Pane.
§  The speaker(s) will chose top questions to answer live at the end of the
webinar.
§  Please post your questions as we go along!
§  Only post your question once; we’ll get to it as we go down the list.
#forcewebinar
Introduction to Apex
§  What is Apex?
§  Developing in your browser
§  Apex Controllers
§  Apex Triggers
§  Other Apex Use Cases
#forcewebinar
Declarative Apps
#forcewebinar
Declarative and Programmatic
Declarative Programmatic
Visualforce Pages
Visualforce Components
Apex Controllers
Apex Triggers
Metadata API
REST API
Bulk API
Workflows
Validation Rules
Approval Processes
Objects
Fields
Relationships
Page Layouts
Record Types
User
Interface
Business
Logic
Data
Model
#forcewebinar
Apex
#forcewebinar
Introduction to Apex
Chapter 1:
§  Object-Oriented Language
§  Dot Notation Syntax
§  Developed, Compiled and Deployed in the Cloud
§  “First Class” Citizen on the Platform
#forcewebinar
Every Object, Every Field: Apex and Visualforce Enabled
Visualforce Pages
Visualforce Components
Apex Controllers
Apex Triggers
Custom UI
Custom Logic
#forcewebinar
Apex Class Structure
Chapter 1:
public with sharing class myControllerExtension implements Util {



private final Account acct;

public Contact newContact {get; set;}

public myControllerExtension(ApexPages.StandardController stdController) {

this.acct = (Account)stdController.getRecord();

}



public PageReference associateNewContact(Id cid) {

newContact = [SELECT Id, Account from Contact WHERE Id =: cid LIMIT 1];

newContact.Account = acct;

update newContact;

}

}

Class and Interface based
Scoped Variables
Inline SOQL
Inline DML
þ
þ
þ
þ
#forcewebinar
Developer Console
•  Browser Based
•  Create and Edit Classes
•  Create and Edit Triggers
•  Run Unit Tests
•  Review Debug Logs
#forcewebinar
Apex Controllers
•  Logic for User Interfaces
•  Custom Controllers or Extensions
•  Transport via:
•  Viewstate
•  JavaScript
#forcewebinar
Interacting with Apex
Annotated Apex methods exposed to JavaScript
Visualforce Forms
Visualforce component bound to an Apex Method
JavaScript Remoting
#forcewebinar
Apex Triggers
§  Event Based Logic
§  Associated with Object Types
§  Before or After:
§  Insert
§  Update
§  Delete
§  Undelete
#forcewebinar
Controlling Flow
trigger LineItemTrigger on Line_Item__c (before insert,	
	 	 	 	 	 	 	 	 	
	 	 	before update) { 



//separate before and after 	
if(Trigger.isBefore) {



//separate events
if(Trigger.isInsert) {	
	 	 System.debug(‘BEFORE INSERT’);	
	 	 	
	 	 DelegateClass.performLogic(Trigger.new);
#forcewebinar
Controlling Flow
trigger LineItemTrigger on Line_Item__c (before insert,	
	 	 	 	 	 	 	 	 	
	 	 	before update) { 



//separate before and after 	
if(Trigger.isBefore) {



//separate events
if(Trigger.isInsert) {	
	 	 System.debug(‘BEFORE INSERT’);	
	 	 	
	 	 DelegateClass.performLogic(Trigger.new);
#forcewebinar
Static Flags
public with sharing class AccUpdatesControl {

// This class is used to set flag to prevent multiple calls

public static boolean calledOnce = false;



public static boolean ProdUpdateTrigger = false;



}
#forcewebinar
Chatter Triggers
trigger AddRegexTrigger on Blacklisted_Word__c (before insert,
before update) {



for (Blacklisted_Word__c f : trigger.new)

{

if(f.Custom_Expression__c != NULL)

{

f.Word__c = '';

f.Match_Whole_Words_Only__c = false;

f.RegexValue__c = f.Custom_Expression__c;

}

}

}
#forcewebinar
Scheduled Apex
#forcewebinar
Schedulable Interface
global with sharing class WarehouseUtil implements Schedulable
{



//General constructor

global WarehouseUtil() {}



//Scheduled execute

global void execute(SchedulableContext ctx) {

//Use static method for checking dated invoices

WarehouseUtil.checkForDatedInvoices(); 

}
#forcewebinar
Schedulable Interface
System.schedule('testSchedule','0 0 13 * * ?',	
	 	new WarehouseUtil());



Via Apex
Via Web UI
#forcewebinar
Batch Apex
#forcewebinar
Batchable Interface
global with sharing class WarehouseUtil 	
	 	implements Database.Batchable<sObject> {



//Batch execute interface

global Database.QueryLocator start(Database.BatchableContext B
//Start on next context

}



global void execute(Database.BatchableContext BC, 	
	 	 	 	 	 	 	 List<sObject> scop
//Execute on current scope

}



global void finish(Database.BatchableContext BC) { 

//Finish and clean up context

}

#forcewebinar
Apex Endpoints
#forcewebinar
Apex REST
@RestResource(urlMapping='/CaseManagement/v1/*')

global with sharing class CaseMgmtService

{



@HttpPost

global static String attachPic(){

RestRequest req = RestContext.request;

RestResponse res = Restcontext.response;

Id caseId =
req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

Blob picture = req.requestBody;

Attachment a = new Attachment (ParentId = caseId,

Body = picture,

ContentType = 'image/
#forcewebinar
Unit Testing
•  Declare Classes/Code as Test
•  isTest Annotation
•  testmethod keyword
•  Default data scope is test only
•  75% coverage required
#forcewebinar
Governor Limits
•  System Level Limits
•  Examples include:
•  150 DML calls
•  10 callouts
•  More in the Apex Workbook
•  Chapter 3, Tutorial #13
#forcewebinar
Bulkify Logic
// For loop to iterate through all the queried Account records !
for(Account a: accountsWithContacts){!
// Use the child relationships dot syntax to access the related Contacts!
for(Contact c: a.Contacts){!
!contactsToUpdate.add(c);!
} !
}!
!
//Now outside the FOR Loop, perform a single Update DML statement. !
update contactsToUpdate; !
!
http://wiki.developerforce.com/page/Apex_Code_Best_Practices
#forcewebinar
Recap
§  What is Apex?
§  Developing in your browser
§  Apex Controllers
§  Apex Triggers
§  Other Apex Use Cases
#forcewebinar
Resources
§  Your Developer Edition
–  http://developer.force.com/join
§  Force.com Workbook
–  http://developer.force.com/workbooks
§  Apex Workbook
–  http://developer.force.com/workbooks
Q & A
#forcewebinar
Joshua
Birk
Developer Evangelist
@joshbirk
LeeAnne
Templeman
Developer Evangelist
@leeanndroid

More Related Content

What's hot (20)

PPTX
10 Principles of Apex Testing
Salesforce Developers
 
PDF
Spring '14 Release Developer Preview Webinar
Salesforce Developers
 
PPTX
Aura Framework and Lightning (Nikolay Zenko and Alexey Filippov)
Yury Bondarau
 
PDF
Oracle apex-hands-on-guide lab#1
Amit Sharma
 
PPTX
Deep Dive into Apex Triggers
Salesforce Developers
 
PDF
Secure Salesforce: Common Secure Coding Mistakes
Salesforce Developers
 
PPTX
sf tools from community
Durgesh Dhoot
 
PDF
Lightning Connect Custom Adapters: Connecting Anything with Salesforce
Salesforce Developers
 
PDF
Getting Started With Apex REST Services
Salesforce Developers
 
PPTX
Mastering the Lightning Framework - Part 1
Salesforce Developers
 
PDF
Local development with Open Source Base Components
Salesforce Developers
 
PPTX
Best Practices for Lightning Apps
Mark Adcock
 
PPTX
Mds cloud saturday 2015 salesforce intro
David Scruggs
 
PPTX
Lightning components performance best practices
Salesforce Developers
 
PDF
Salesforce API Series: Integrating Applications with Force.com Webinar
Salesforce Developers
 
PDF
Introduction to Visualforce
Salesforce Developers
 
PDF
Abap proxies
szchowdhury
 
PDF
Force.com migration utility
Amit Sharma
 
PDF
Salesforce API Series: Release Management with the Metadata API webinar
Salesforce Developers
 
PDF
User and group security migration
Amit Sharma
 
10 Principles of Apex Testing
Salesforce Developers
 
Spring '14 Release Developer Preview Webinar
Salesforce Developers
 
Aura Framework and Lightning (Nikolay Zenko and Alexey Filippov)
Yury Bondarau
 
Oracle apex-hands-on-guide lab#1
Amit Sharma
 
Deep Dive into Apex Triggers
Salesforce Developers
 
Secure Salesforce: Common Secure Coding Mistakes
Salesforce Developers
 
sf tools from community
Durgesh Dhoot
 
Lightning Connect Custom Adapters: Connecting Anything with Salesforce
Salesforce Developers
 
Getting Started With Apex REST Services
Salesforce Developers
 
Mastering the Lightning Framework - Part 1
Salesforce Developers
 
Local development with Open Source Base Components
Salesforce Developers
 
Best Practices for Lightning Apps
Mark Adcock
 
Mds cloud saturday 2015 salesforce intro
David Scruggs
 
Lightning components performance best practices
Salesforce Developers
 
Salesforce API Series: Integrating Applications with Force.com Webinar
Salesforce Developers
 
Introduction to Visualforce
Salesforce Developers
 
Abap proxies
szchowdhury
 
Force.com migration utility
Amit Sharma
 
Salesforce API Series: Release Management with the Metadata API webinar
Salesforce Developers
 
User and group security migration
Amit Sharma
 

Viewers also liked (20)

PPTX
Introduction to apex code
EdwinOstos
 
PPTX
Introduction to Apex for Developers
Salesforce Developers
 
PDF
Apex code-fundamentals
Amit Sharma
 
PPTX
Introduction to Apache Apex
Apache Apex
 
PPT
Salesforce Presentation
Chetna Purohit
 
PDF
Alt tab - better apex tabs
Enkitec
 
PDF
High Reliability DML and Concurrency Design Patterns for Apex
Salesforce Developers
 
PPTX
APEX navigation concepts
Tobias Arnhold
 
PPTX
Apex - How to create a master detail form
Viveka Solutions
 
PPTX
Atl elevate programmatic developer slides
David Scruggs
 
PPTX
Triggers for Admins: A Five-step Framework for Creating Triggers
Salesforce Developers
 
DOCX
Interview questions
mallareddy0107
 
PPTX
Hands-On Workshop: Introduction to Development on Force.com for Developers
Salesforce Developers
 
PPTX
Apex for Admins: Beyond the Basics
Salesforce Developers
 
ODP
Workflow in Salesforce
MST Solutions LLC
 
PPTX
Visualforce for the Salesforce1 Platform
sg8002
 
PPTX
Coding the Salesforce1 Platform
sg8002
 
PDF
Salesforce Developer Workshop for GDF Suez Hackathon
Peter Chittum
 
PPTX
How to Get Started with Salesforce Lightning
Salesforce Admins
 
PPT
What you need to know on Force.com in 10 slides
Guillaume Windels
 
Introduction to apex code
EdwinOstos
 
Introduction to Apex for Developers
Salesforce Developers
 
Apex code-fundamentals
Amit Sharma
 
Introduction to Apache Apex
Apache Apex
 
Salesforce Presentation
Chetna Purohit
 
Alt tab - better apex tabs
Enkitec
 
High Reliability DML and Concurrency Design Patterns for Apex
Salesforce Developers
 
APEX navigation concepts
Tobias Arnhold
 
Apex - How to create a master detail form
Viveka Solutions
 
Atl elevate programmatic developer slides
David Scruggs
 
Triggers for Admins: A Five-step Framework for Creating Triggers
Salesforce Developers
 
Interview questions
mallareddy0107
 
Hands-On Workshop: Introduction to Development on Force.com for Developers
Salesforce Developers
 
Apex for Admins: Beyond the Basics
Salesforce Developers
 
Workflow in Salesforce
MST Solutions LLC
 
Visualforce for the Salesforce1 Platform
sg8002
 
Coding the Salesforce1 Platform
sg8002
 
Salesforce Developer Workshop for GDF Suez Hackathon
Peter Chittum
 
How to Get Started with Salesforce Lightning
Salesforce Admins
 
What you need to know on Force.com in 10 slides
Guillaume Windels
 
Ad

Similar to Intro to Apex Programmers (20)

PPTX
Intro to Apex - Salesforce Force Friday Webinar
Abhinav Gupta
 
PPTX
Advanced Apex Webinar
pbattisson
 
PPTX
Dive Deep into Apex: Advanced Apex!
Salesforce Developers
 
PPTX
Force.com Friday : Intro to Apex
Salesforce Developers
 
PPTX
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Salesforce Developers
 
PPT
Salesforce1 Platform for programmers
Salesforce Developers
 
PDF
Force.com Friday: Intro to Force.com
Salesforce Developers
 
PPTX
Apex for Admins: Beyond the Basics (Part 2)
Salesforce Developers
 
PPTX
ELEVATE Paris
Peter Chittum
 
PPTX
Elevate Tel Aviv
sready
 
PPTX
Coding Apps in the Cloud with Force.com - Part I
Salesforce Developers
 
PPTX
Mastering Force.com: Advanced Visualforce
Salesforce Developers
 
PPTX
Hands-On Workshop: Introduction to Coding for on Force.com for Admins and Non...
Salesforce Developers
 
PDF
Winter 14 Release Developer Preview
Salesforce Developers
 
PPTX
Coding Apps in the Cloud with Force.com - Part 2
Salesforce Developers
 
PDF
Elevate london dec 2014.pptx
Peter Chittum
 
PDF
Summer '13 Developer Preview Webinar
Salesforce Developers
 
PDF
Introduction to Apex Triggers
Salesforce Developers
 
PPTX
Javascript and Remote Objects on Force.com Winter 15
Peter Chittum
 
PDF
Introduction to Apex Triggers
Salesforce Developers
 
Intro to Apex - Salesforce Force Friday Webinar
Abhinav Gupta
 
Advanced Apex Webinar
pbattisson
 
Dive Deep into Apex: Advanced Apex!
Salesforce Developers
 
Force.com Friday : Intro to Apex
Salesforce Developers
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Salesforce Developers
 
Salesforce1 Platform for programmers
Salesforce Developers
 
Force.com Friday: Intro to Force.com
Salesforce Developers
 
Apex for Admins: Beyond the Basics (Part 2)
Salesforce Developers
 
ELEVATE Paris
Peter Chittum
 
Elevate Tel Aviv
sready
 
Coding Apps in the Cloud with Force.com - Part I
Salesforce Developers
 
Mastering Force.com: Advanced Visualforce
Salesforce Developers
 
Hands-On Workshop: Introduction to Coding for on Force.com for Admins and Non...
Salesforce Developers
 
Winter 14 Release Developer Preview
Salesforce Developers
 
Coding Apps in the Cloud with Force.com - Part 2
Salesforce Developers
 
Elevate london dec 2014.pptx
Peter Chittum
 
Summer '13 Developer Preview Webinar
Salesforce Developers
 
Introduction to Apex Triggers
Salesforce Developers
 
Javascript and Remote Objects on Force.com Winter 15
Peter Chittum
 
Introduction to Apex Triggers
Salesforce Developers
 
Ad

More from Salesforce Developers (20)

PDF
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Salesforce Developers
 
PDF
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Salesforce Developers
 
PPTX
TrailheaDX India : Developer Highlights
Salesforce Developers
 
PDF
Why developers shouldn’t miss TrailheaDX India
Salesforce Developers
 
PPTX
CodeLive: Build Lightning Web Components faster with Local Development
Salesforce Developers
 
PPTX
CodeLive: Converting Aura Components to Lightning Web Components
Salesforce Developers
 
PPTX
Enterprise-grade UI with open source Lightning Web Components
Salesforce Developers
 
PPTX
TrailheaDX and Summer '19: Developer Highlights
Salesforce Developers
 
PDF
Live coding with LWC
Salesforce Developers
 
PDF
Lightning web components - Episode 4 : Security and Testing
Salesforce Developers
 
PDF
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
PDF
Lightning web components episode 2- work with salesforce data
Salesforce Developers
 
PDF
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
PDF
Migrating CPQ to Advanced Calculator and JSQCP
Salesforce Developers
 
PDF
Scale with Large Data Volumes and Big Objects in Salesforce
Salesforce Developers
 
PDF
Replicate Salesforce Data in Real Time with Change Data Capture
Salesforce Developers
 
PDF
Modern Development with Salesforce DX
Salesforce Developers
 
PDF
Get Into Lightning Flow Development
Salesforce Developers
 
PDF
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
PDF
Introduction to MuleSoft
Salesforce Developers
 
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Salesforce Developers
 
TrailheaDX India : Developer Highlights
Salesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Salesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
Salesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
Salesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Salesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
Salesforce Developers
 
Live coding with LWC
Salesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Salesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
Lightning web components episode 2- work with salesforce data
Salesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Salesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Salesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Salesforce Developers
 
Modern Development with Salesforce DX
Salesforce Developers
 
Get Into Lightning Flow Development
Salesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
Introduction to MuleSoft
Salesforce Developers
 

Recently uploaded (20)

PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Digital Circuits, important subject in CS
contactparinay1
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 

Intro to Apex Programmers

  • 1. Introduction to Apex for Programmers March 27, 2014
  • 2. #forcewebinar Safe Harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of intellectual property and other litigation, risks associated with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non- salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended July 31, 2012. This documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 4. #forcewebinar Follow Developer Force for the Latest News @forcedotcom / #forcewebinar Developer Force – Force.com Community Developer Force Developer Force Group +Developer Force – Force.com Community
  • 5. #forcewebinar Have Questions? §  We have an expert support team at the ready to answer your questions during the webinar. §  Ask your questions via the GoToWebinar Questions Pane. §  The speaker(s) will chose top questions to answer live at the end of the webinar. §  Please post your questions as we go along! §  Only post your question once; we’ll get to it as we go down the list.
  • 6. #forcewebinar Introduction to Apex §  What is Apex? §  Developing in your browser §  Apex Controllers §  Apex Triggers §  Other Apex Use Cases
  • 8. #forcewebinar Declarative and Programmatic Declarative Programmatic Visualforce Pages Visualforce Components Apex Controllers Apex Triggers Metadata API REST API Bulk API Workflows Validation Rules Approval Processes Objects Fields Relationships Page Layouts Record Types User Interface Business Logic Data Model
  • 10. #forcewebinar Introduction to Apex Chapter 1: §  Object-Oriented Language §  Dot Notation Syntax §  Developed, Compiled and Deployed in the Cloud §  “First Class” Citizen on the Platform
  • 11. #forcewebinar Every Object, Every Field: Apex and Visualforce Enabled Visualforce Pages Visualforce Components Apex Controllers Apex Triggers Custom UI Custom Logic
  • 12. #forcewebinar Apex Class Structure Chapter 1: public with sharing class myControllerExtension implements Util {
 
 private final Account acct;
 public Contact newContact {get; set;}
 public myControllerExtension(ApexPages.StandardController stdController) {
 this.acct = (Account)stdController.getRecord();
 }
 
 public PageReference associateNewContact(Id cid) {
 newContact = [SELECT Id, Account from Contact WHERE Id =: cid LIMIT 1];
 newContact.Account = acct;
 update newContact;
 }
 }
 Class and Interface based Scoped Variables Inline SOQL Inline DML þ þ þ þ
  • 13. #forcewebinar Developer Console •  Browser Based •  Create and Edit Classes •  Create and Edit Triggers •  Run Unit Tests •  Review Debug Logs
  • 14. #forcewebinar Apex Controllers •  Logic for User Interfaces •  Custom Controllers or Extensions •  Transport via: •  Viewstate •  JavaScript
  • 15. #forcewebinar Interacting with Apex Annotated Apex methods exposed to JavaScript Visualforce Forms Visualforce component bound to an Apex Method JavaScript Remoting
  • 16. #forcewebinar Apex Triggers §  Event Based Logic §  Associated with Object Types §  Before or After: §  Insert §  Update §  Delete §  Undelete
  • 17. #forcewebinar Controlling Flow trigger LineItemTrigger on Line_Item__c (before insert, before update) { 
 
 //separate before and after if(Trigger.isBefore) {
 
 //separate events if(Trigger.isInsert) { System.debug(‘BEFORE INSERT’); DelegateClass.performLogic(Trigger.new);
  • 18. #forcewebinar Controlling Flow trigger LineItemTrigger on Line_Item__c (before insert, before update) { 
 
 //separate before and after if(Trigger.isBefore) {
 
 //separate events if(Trigger.isInsert) { System.debug(‘BEFORE INSERT’); DelegateClass.performLogic(Trigger.new);
  • 19. #forcewebinar Static Flags public with sharing class AccUpdatesControl {
 // This class is used to set flag to prevent multiple calls
 public static boolean calledOnce = false;
 
 public static boolean ProdUpdateTrigger = false;
 
 }
  • 20. #forcewebinar Chatter Triggers trigger AddRegexTrigger on Blacklisted_Word__c (before insert, before update) {
 
 for (Blacklisted_Word__c f : trigger.new)
 {
 if(f.Custom_Expression__c != NULL)
 {
 f.Word__c = '';
 f.Match_Whole_Words_Only__c = false;
 f.RegexValue__c = f.Custom_Expression__c;
 }
 }
 }
  • 22. #forcewebinar Schedulable Interface global with sharing class WarehouseUtil implements Schedulable {
 
 //General constructor
 global WarehouseUtil() {}
 
 //Scheduled execute
 global void execute(SchedulableContext ctx) {
 //Use static method for checking dated invoices
 WarehouseUtil.checkForDatedInvoices(); 
 }
  • 23. #forcewebinar Schedulable Interface System.schedule('testSchedule','0 0 13 * * ?', new WarehouseUtil());
 
 Via Apex Via Web UI
  • 25. #forcewebinar Batchable Interface global with sharing class WarehouseUtil implements Database.Batchable<sObject> {
 
 //Batch execute interface
 global Database.QueryLocator start(Database.BatchableContext B //Start on next context
 }
 
 global void execute(Database.BatchableContext BC, List<sObject> scop //Execute on current scope
 }
 
 global void finish(Database.BatchableContext BC) { 
 //Finish and clean up context
 }

  • 27. #forcewebinar Apex REST @RestResource(urlMapping='/CaseManagement/v1/*')
 global with sharing class CaseMgmtService
 {
 
 @HttpPost
 global static String attachPic(){
 RestRequest req = RestContext.request;
 RestResponse res = Restcontext.response;
 Id caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
 Blob picture = req.requestBody;
 Attachment a = new Attachment (ParentId = caseId,
 Body = picture,
 ContentType = 'image/
  • 28. #forcewebinar Unit Testing •  Declare Classes/Code as Test •  isTest Annotation •  testmethod keyword •  Default data scope is test only •  75% coverage required
  • 29. #forcewebinar Governor Limits •  System Level Limits •  Examples include: •  150 DML calls •  10 callouts •  More in the Apex Workbook •  Chapter 3, Tutorial #13
  • 30. #forcewebinar Bulkify Logic // For loop to iterate through all the queried Account records ! for(Account a: accountsWithContacts){! // Use the child relationships dot syntax to access the related Contacts! for(Contact c: a.Contacts){! !contactsToUpdate.add(c);! } ! }! ! //Now outside the FOR Loop, perform a single Update DML statement. ! update contactsToUpdate; ! ! http://wiki.developerforce.com/page/Apex_Code_Best_Practices
  • 31. #forcewebinar Recap §  What is Apex? §  Developing in your browser §  Apex Controllers §  Apex Triggers §  Other Apex Use Cases
  • 32. #forcewebinar Resources §  Your Developer Edition –  http://developer.force.com/join §  Force.com Workbook –  http://developer.force.com/workbooks §  Apex Workbook –  http://developer.force.com/workbooks
  • 33. Q & A #forcewebinar Joshua Birk Developer Evangelist @joshbirk LeeAnne Templeman Developer Evangelist @leeanndroid