Upload
salesforce
View
2.653
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
1
Introduction to Apex for
Non-Developers
Leah McGowen-Hare Senior Technical Instructor, Force.com
David Reece Technical Instructor
2
Safe Harbor Statement
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If
any such uncertainties materialize or if any of the assumptions prove 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 statements, including: any
projections of earnings, revenues, or other financial items; any statements regarding strategies or plans of
management for future operations; any statements concerning new, planned, or upgraded services or
developments; statements about current or future economic conditions; and any statements of belief.
The risks and uncertainties referred to above include - but are not limited to - risks associated with 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 immature market in which we
operate; our relatively limited operating history; our ability to expand, retain, and motivate our employees and
manage our growth; risks associated with new releases of our service; and risks associated with selling to larger
enterprise customers. Further information on potential factors that could affect the financial results of
salesforce.com, inc. are included in our registration statement (on Form S-1) and in other filings with the
Securities and Exchange Commission. These documents are available on the SEC Filings section of our Web
site.
Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Any unreleased services or features referenced in this or other 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.
Org will be active for 30 days post Cloudforce Training Org Login
Username: admin@cflon12apex###.com
Password: cf2012
Example: Your three digit number = 010
Your username = [email protected]
For ###: use the 3-digit
number on the cover of
your exercise guide
3
Agenda
What is Apex?
Apex Classes
Collections
Exercise 1: Creating a Class
Invoking Apex
Apex Triggers
Exercise 2: Creating a Trigger
Q & A
What is Apex?
Object-Oriented
Objects are discrete “bundles”
of code modeled after things in
the real world.
On-Demand
Functionality that you need,
when you need it.
Automatically plugged into other
Force.com platform features.
Apex is an object-oriented, on-demand programming language.
4
When to Use Apex
… then create an Apex …
Trigger
Trigger
Trigger
Custom Controller
Custom Web Service
Email Service
Custom Controller
Need a more powerful …
Validation Rule
Workflow Rule
Sharing/Assignment Rule
Standard Controller
Standard Web Service
Email to Case/Lead
Report/Report Type
Classes have: Attributes (characteristics).
Methods (actions).
A unique class name.
Classes are represented by a code block
surrounded by curly braces.
Apex Classes
1
2
3
public class Human{ // The body of the class }
Classes are blueprints used to create objects in code. classes
5
Collections create virtual data
structures in memory so that
Apex can access records. Lists are ordered collections of
a single datatype.
Each item in a list contains an
index and a value.
Collections
1 List<DataType> listName = new List<DataType>();
2 List<Human> cloudforceAttendeess = new List<Human>();
3 List<Accounts> newAccounts = new List<Accounts>();
Hands-on Exercise
Task:
Create the HelloWorldPositionClass
to update the Hello field.
Exercise 1:Creating a Hello World Apex Class
HelloWorldPositionClass
For each Position record in input,
set Hello__c = ‘World!’ classes
6
Invoking Apex
Saving a
record
via UI
Saving records
via API
classes
DML Operations
triggers
Sending
an email Submitting an
anonymous block
via API
Creating a job via
Apex Scheduler
Interacting with a
Visualforce page
Web Service
Client makes
a call
classes
anon. blocks
Invoking an Apex
Web Service pages
Triggers
Triggers execute when records are saved through either: – The user interface.
– The Web Services API.
Triggers can call classes.
A trigger is an Apex script that executes before or
after a DML operation on a single sObject.
1
2
3
trigger triggerName on ObjectName (triggerEvent1, triggerEvent2…) {
//code_block
}
triggers
7
Trigger context refers to the records that cause a trigger
to execute. Trigger.new: a list of the new versions of sObjects
Trigger.old: a list of the old versions of sObjects
These attributes capture the data that’s
being processed and place it in a list
that you can work with.
Trigger Context
Hands-on Exercise
Task:
Create the HelloWorldPositionTrigger to call the class.
Exercise 2: Creating a Hello World Apex Trigger
HelloWorldPositionClass
Trigger.new
HelloWorldPositionTrigger
before insert
before update
Exercise 1
triggers
classes
8
Key Takeaways
Apex can be used to extend
business processes within your
Salesforce organization.
Classes are like blueprints and
have methods and attributes.
Triggers execute when records
are saved.
Apex can access lists of records
stored in memory.
Follow up with an instructor-led course, we suggest:
Introduction to Object Oriented Programming
Ready for more hands-on training?
What’s Next?
Have Premier?
Take a great online class, we suggest:
APEX
Don’t forget..
Tell us what you think with the
session survey
Visit us in the Cloud Expo for your
10% off training voucher!
9
Question and Answer