SlideShare a Scribd company logo
Introduction to Apex Triggers
Arming the Dangerous
Iman Maghroori, Principal Sales Engineer
@IMaghroori
Doug Merrett, Principal Architect
@justinbeiber
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 any
litigation, risks associated with completed and any 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-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent
fiscal quarter. These 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.
Iman Maghroori
Principal Sales Engineer
@IMaghroori
Doug Merrett
Principal Architect – Northern Europe
@justinbeiber
Here is the Plan
What is a
Trigger?
When / Why
Trigger
Deconstruction

Tools
Resources

Q&A
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?
What is a Trigger?
What is a Trigger?

“…is procedural code that is
automatically executed in response
to certain events in a database…”
- Wikipedia
What is a Trigger?

“ …custom code that fires
when a record is created,
updated or deleted.”

-Iman Maghroori
What Happens When You Hit “Save”?
What Happens When You Hit “Save”?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.

Old values are overwritten
System Validation Rules
Apex (before) triggers
Custom Validation Rules
Record saved to DB (not committed)
Record reloaded from DB
Apex (after) triggers
Assignment Rules
Auto-Response Rules
Workflow Rules
Escalation Rules
Rollup Summary Formulas updated
Database Commit
Post-commit logic (Sending emails)
Now You’re Dangerous…
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
Workflow Can…
Update Fields
Assign Tasks
Send Emails
Send Outbound Messages (Integrations)
Workflow Cannot…
Create Other Records
 Automatically create child records

Complex Calculations
 Calculate total revenue from child accounts

Automatically Submit Records for Approval
Delete Records
Apex: The Programming Language of Force.com
Object-oriented language
Java-like syntax
6 Billion+ Lines of Apex
Why Apex?
Runs in the Cloud
Integrated to Your Data
Lots of prebuilt capability
Testing Framework

Backward Compatibility
The Force.com Platform is a Multi-Tenant Environment
Use Case: UberJet
Create Invoice Trigger
Introduction to Apex Triggers
Mark the Jet as Booked Trigger
Test Your Code!
75% Minimum Code Coverage Before You Deploy
We check for the %, you should check for all the possible use cases.
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
Next Steps to Level Up
• Developer Environment
• Apex Workbook
• To Learn More
Where Can I Go for Help?
•
•
•
•
•
•
•

Developer.force.com
Salesforce.com Training / Certifications
Code Share
Developer Community
Apex Guide
Security Information
Help & Training
Take it to the Next Level: Professional Services
Any Questions?
Introduction to Apex Triggers

More Related Content

PDF
Introduction to Apex Triggers
PDF
Lightning Data Service: Eliminate Your Need to Load Records Through Controllers
PPTX
10 Principles of Apex Testing
PPTX
Intro to Lightning Components - Dreamforce 2016
PPTX
Building a Single Page App with Lightning Components
PDF
Integrations with the Force.com Platform Using Custom Apex REST Services
PPTX
Migrating Visualforce Pages to Lightning
PPTX
Lightning Components Introduction
Introduction to Apex Triggers
Lightning Data Service: Eliminate Your Need to Load Records Through Controllers
10 Principles of Apex Testing
Intro to Lightning Components - Dreamforce 2016
Building a Single Page App with Lightning Components
Integrations with the Force.com Platform Using Custom Apex REST Services
Migrating Visualforce Pages to Lightning
Lightning Components Introduction

What's hot (20)

PPTX
Lightning components performance best practices
PDF
Advanced Lightning Components
PDF
Write bulletproof trigger code
PDF
Lightning Components - Advanced Features
PPTX
Building apps faster with lightning and winter '17
PPTX
Using Apex for REST Integration
PDF
SLDS and Lightning Components
PPTX
Secure Development on the Salesforce Platform - Part 2
PPTX
Process Automation on Lightning Platform Workshop
PDF
Build Amazing Website without coding using Salesforce SiteForce
PDF
Secure Salesforce: Lightning Components Best Practices
PPTX
Secure Development on the Salesforce Platform - Part 3
PPTX
Build Consumer-Facing Apps with Heroku Connect
PDF
Unlocking the Hidden Potential of Salesforce Live Agent
PPTX
Understanding Salesforce Streaming API
PPTX
Introduction to lightning out df16
PPTX
Integrating with salesforce
PDF
Salesforce API Series: Integrating Applications with Force.com Webinar
PPTX
Winter '16 Release - Overview and Highlights
PPTX
TrailheaDX India : Developer Highlights
Lightning components performance best practices
Advanced Lightning Components
Write bulletproof trigger code
Lightning Components - Advanced Features
Building apps faster with lightning and winter '17
Using Apex for REST Integration
SLDS and Lightning Components
Secure Development on the Salesforce Platform - Part 2
Process Automation on Lightning Platform Workshop
Build Amazing Website without coding using Salesforce SiteForce
Secure Salesforce: Lightning Components Best Practices
Secure Development on the Salesforce Platform - Part 3
Build Consumer-Facing Apps with Heroku Connect
Unlocking the Hidden Potential of Salesforce Live Agent
Understanding Salesforce Streaming API
Introduction to lightning out df16
Integrating with salesforce
Salesforce API Series: Integrating Applications with Force.com Webinar
Winter '16 Release - Overview and Highlights
TrailheaDX India : Developer Highlights
Ad

Similar to Introduction to Apex Triggers (20)

PDF
Introduction to Apex Triggers
PPTX
Deep Dive into Apex Triggers
PPTX
Force.com Friday : Intro to Apex
PPT
Apex Trigger Debugging: Solving the Hard Problems
PPTX
Orchestrate all of your salesforce automation with the trigger actions framework
PPTX
Intro to Apex - Salesforce Force Friday Webinar
PPTX
Partition Your (Apex) Trigger Logic Using Metadata
PDF
Intro to Apex Programmers
PPTX
Route your triggers like a pro #DF18
PDF
Decoding Triggers for Admins
PPTX
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
PPTX
Apex for Admins: Beyond the Basics (Part 2)
PDF
Introduction to Force.com
PPTX
Triggers for Admins: A Five-step Framework for Creating Triggers
PPTX
Elevate Madrid Essentials - Advance Track
PDF
Apex Nuances: Transitioning to Force.com Development
PDF
TrailheaDX 2019 : Truly Asynchronous Apex Triggers using Change Data Capture
PPTX
An Admin's Guide to the Developer Console by Francis Pindar
PDF
Webinar Coding for Salesforce Admins
PPTX
Apex for Admins: Beyond the Basics
Introduction to Apex Triggers
Deep Dive into Apex Triggers
Force.com Friday : Intro to Apex
Apex Trigger Debugging: Solving the Hard Problems
Orchestrate all of your salesforce automation with the trigger actions framework
Intro to Apex - Salesforce Force Friday Webinar
Partition Your (Apex) Trigger Logic Using Metadata
Intro to Apex Programmers
Route your triggers like a pro #DF18
Decoding Triggers for Admins
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Beyond the Basics (Part 2)
Introduction to Force.com
Triggers for Admins: A Five-step Framework for Creating Triggers
Elevate Madrid Essentials - Advance Track
Apex Nuances: Transitioning to Force.com Development
TrailheaDX 2019 : Truly Asynchronous Apex Triggers using Change Data Capture
An Admin's Guide to the Developer Console by Francis Pindar
Webinar Coding for Salesforce Admins
Apex for Admins: Beyond the Basics
Ad

More from Salesforce Developers (20)

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

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
KodekX | Application Modernization Development
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
KodekX | Application Modernization Development
sap open course for s4hana steps from ECC to s4
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Network Security Unit 5.pdf for BCA BBA.
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars

Introduction to Apex Triggers

  • 1. Introduction to Apex Triggers Arming the Dangerous Iman Maghroori, Principal Sales Engineer @IMaghroori Doug Merrett, Principal Architect @justinbeiber
  • 2. 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 any litigation, risks associated with completed and any 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-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These 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.
  • 3. Iman Maghroori Principal Sales Engineer @IMaghroori
  • 4. Doug Merrett Principal Architect – Northern Europe @justinbeiber
  • 5. Here is the Plan What is a Trigger? When / Why Trigger Deconstruction Tools Resources Q&A
  • 6. 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?
  • 7. What is a Trigger?
  • 8. What is a Trigger? “…is procedural code that is automatically executed in response to certain events in a database…” - Wikipedia
  • 9. What is a Trigger? “ …custom code that fires when a record is created, updated or deleted.” -Iman Maghroori
  • 10. What Happens When You Hit “Save”?
  • 11. What Happens When You Hit “Save”? 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. Old values are overwritten System Validation Rules Apex (before) triggers Custom Validation Rules Record saved to DB (not committed) Record reloaded from DB Apex (after) triggers Assignment Rules Auto-Response Rules Workflow Rules Escalation Rules Rollup Summary Formulas updated Database Commit Post-commit logic (Sending emails)
  • 13. 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
  • 14. Workflow Can… Update Fields Assign Tasks Send Emails Send Outbound Messages (Integrations)
  • 15. Workflow Cannot… Create Other Records  Automatically create child records Complex Calculations  Calculate total revenue from child accounts Automatically Submit Records for Approval Delete Records
  • 16. Apex: The Programming Language of Force.com Object-oriented language Java-like syntax 6 Billion+ Lines of Apex
  • 17. Why Apex? Runs in the Cloud Integrated to Your Data Lots of prebuilt capability Testing Framework Backward Compatibility
  • 18. The Force.com Platform is a Multi-Tenant Environment
  • 22. Mark the Jet as Booked Trigger
  • 24. 75% Minimum Code Coverage Before You Deploy We check for the %, you should check for all the possible use cases.
  • 25. 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
  • 26. Next Steps to Level Up • Developer Environment • Apex Workbook • To Learn More
  • 27. Where Can I Go for Help? • • • • • • • Developer.force.com Salesforce.com Training / Certifications Code Share Developer Community Apex Guide Security Information Help & Training Take it to the Next Level: Professional Services