+ All Categories
Home > Documents > Introduction to Apex Triggers

Introduction to Apex Triggers

Date post: 07-Dec-2014
Category:
Upload: salesforce-developers
View: 871 times
Download: 1 times
Share this document with a friend
Description:
 
Popular Tags:
32
Introduction to Apex Triggers Arming the Dangerous Iman Maghroori, Lead Sales Engineer @IMaghroori Josh Kaplan, Senior Product Manager @JoshSFDC
Transcript
Page 1: Introduction to Apex Triggers

Introduction to Apex Triggers

Arming the Dangerous

Iman Maghroori, Lead Sales Engineer

@IMaghroori

Josh Kaplan, Senior Product Manager

@JoshSFDC

Page 2: Introduction to Apex Triggers

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.

Page 3: Introduction to Apex Triggers

Iman Maghroori

Lead Sales Engineer

@IMaghroori

Page 4: Introduction to Apex Triggers

Josh Kaplan

Senior Product Manager

@JoshSFDC

Page 5: Introduction to Apex Triggers

Here is the Plan

When / Why

What is a

Trigger?

Trigger

Deconstruction

Tools

Resources

Q&A

Page 6: Introduction to Apex Triggers

SURVEY: RAISE YOUR HAND IF YOU’VE…

Created a Custom Field?

Created a Workflow/Approval rules?

Written any code before?

Written Apex code?

Written a Trigger before?

Page 7: Introduction to Apex Triggers

What is a Trigger?

Page 8: Introduction to Apex Triggers

What is a Trigger?

“…is procedural code that is

automatically executed in response

to certain events in a database…” - Wikipedia

Page 9: Introduction to Apex Triggers

What is a Trigger?

“ …custom code that fires

when a record is created,

updated or deleted.” -Iman Maghroori

Page 10: Introduction to Apex Triggers

What Happens When You Hit “Save”?

Page 11: Introduction to Apex Triggers

What Happens When You Hit “Save”?

1. Old values are overwritten

2. System Validation Rules

3. Apex (before) triggers

4. Custom Validation Rules

5. Record saved to DB (not committed)

6. Record reloaded from DB

7. Apex (after) triggers

8. Assignment Rules

9. Auto-Response Rules

10. Workflow Rules

11. Escalation Rules

12. Rollup Summary Formulas updated

13. Database Commit

14. Post-commit logic (Sending emails)

Page 12: Introduction to Apex Triggers

Now You’re Dangerous…

Page 13: Introduction to Apex Triggers

When Should You Use Triggers?

• When all other options fail

• Don’t write code if you don’t have to

• Easier to maintain

• Easier to change

• Faster to deploy

Page 14: Introduction to Apex Triggers

Workflow Can…

• Update Fields

• Assign Tasks

• Send Emails

• Send Outbound Messages (Integrations)

Page 15: Introduction to Apex Triggers

Workflow Cannot…

• Create Other Records – Automatically create child records.

• Complex Calculations – Calculate total revenue from child accounts

• Automatically Submit Records for Approval

• Delete Records

Page 16: Introduction to Apex Triggers

Apex: The Programming Language of Force.com

Object-oriented language

Java-like syntax

2.5 Billion Lines Of Apex

Page 17: Introduction to Apex Triggers

Why Apex?

Runs in the Cloud

Integrated to Your Data

Convenience Features

Testing Framework

Backward Compatibility

Page 18: Introduction to Apex Triggers

The Force.com Platform is a Multi-Tenant Environment

Page 19: Introduction to Apex Triggers

Use Case: UberJet

Page 20: Introduction to Apex Triggers
Page 21: Introduction to Apex Triggers

Create Invoice Trigger

Page 22: Introduction to Apex Triggers
Page 23: Introduction to Apex Triggers

Reserve Jet Trigger

Page 24: Introduction to Apex Triggers
Page 25: Introduction to Apex Triggers

User Email Trigger

Page 26: Introduction to Apex Triggers

Test Your Code!

Workflow Can…

• Update Fields

• Assign Tasks

• Send Emails

• Send Outbound

Page 27: Introduction to Apex Triggers

75% Minimum Code Coverage Before You Deploy

We check for the %, you should check for all the possible use cases.

Page 28: Introduction to Apex Triggers

How to Deploy to Production?

• Make sure your code passes the tests & test coverage

• Create an “Outbound Change Set” and add your updates to it

• Push the Outbound Change Set to your Production Environment

• Accept the Inbound Change Set in your Production Environment.

• Setup->Deploy->Inbound Change Sets -> [Change Set] -> Deploy

Page 29: Introduction to Apex Triggers

Next Steps to Level Up

• Developer Environment

• Apex Workbook

• To Learn More

Page 31: Introduction to Apex Triggers

Any Questions?

Page 32: Introduction to Apex Triggers

Recommended