SlideShare a Scribd company logo
Introduction to
Apex Testing
lmeerkatz@salesforce.com
@meerkatz
alincoln@salesforce.com
Laura Meerkatz
Developer
Salesforce.org
Adam Lincoln
Developer
Salesforce.org
Forward-Looking Statements
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.
Agenda
Why do we write tests?
What to test
Best practices
Resources
Q&A
1
2
3
4
5
Poll!
Why do we test?
Test basics
What goes into each test class
Test Structure
What to test
What to test
Things that should happen do happen (positive)
Things that shouldn’t happen don’t happen (negative)
User access
Exceptions
Bulk testing
1
2
3
4
5
Calculate employee bonuses
Sample scenario
• Employees are awarded a 1% bonus based on the
amount of closed won opportunities they own
• The maximum bonus is $25,000
• Only admins can retotal bonuses
• A negative total opportunity amount should result in an
exception
Verify that the things that should happen do happen
Positive Tests
Verify that the things that should happen do happen
Positive Tests
Verify that the things that should not happen don’t happen
Negative Tests
Verify that the things that should not happen don’t happen
Negative Tests
Verify that users can’t do things they don’t have permission to do
Use System.runAs() to test user access
Verify when your code should be throwing an exception
Exception Testing
Verify that your code will work when several records are updated at once
Bulk Testing
Test Data
Avoid using SeeAllData=true
Create data for tests
Sometimes you have to use SeeAllData=true
There are exceptions
Set up your test data in one place so you can reuse it everywhere
Use Test Data Factories
Set up test data for all methods in one place
Use @TestSetup
Reset governor limits
Use Test.startTest()/Test.stopTest()
Running Tests
Summary
• Tests help you sleep better at night!
• Test for things that should happen and things that shouldn’t
happen
• Use test data factories and @TestSetup to make creating
test data easy
• Use developer console to run individual tests and see
coverage
Resources
tinyurl.com/df16apextests
Questions?
Thank Y u

More Related Content

What's hot (20)

PDF
Easy No-Code Integrations with External Services and Visual Flow
Salesforce Developers
 
PDF
Webinar: Cut that Clutter! Maintain a Clean Org and Improve Productivity
Salesforce Admins
 
PDF
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
PDF
New from Salesforce Labs
Salesforce Admins
 
PDF
Introduction to Einstein Bots
Salesforce Developers
 
PDF
Spring '18 開発者向け新機能
Salesforce Developers Japan
 
PPTX
Rollin' Out Lightnin' Ain't All That Frightenin' by Jon Barlow
Salesforce Admins
 
PDF
アドバンスドLightningコンポーネント:品質の高いコンポーネント開発のためのTips
Salesforce Developers Japan
 
PDF
Salesforce for Admins Keynote - Dreamforce 2016
Salesforce Admins
 
PDF
はじめようLightning Component開発
Salesforce Developers Japan
 
PPTX
Dallas Salesforce User Group Meeting - March 2011 (Sponsored by Statera)
Kevin Richardson
 
PDF
#DF17Recap series: Make apps smarter with Einstein
Salesforce Developers
 
PDF
Webinar: 5 Game Changing Lightning Components on AppExchange
Salesforce Admins
 
PDF
Build Your Lightning Rollout Plan - September 2017
Salesforce Admins
 
PDF
Winter '19 開発者向け新機能
Salesforce Developers Japan
 
PPTX
I Built in Lightning and I Liked It
Salesforce Admins
 
PDF
Salesforce Known Issues: The Lifecycle of a Bug
Salesforce Developers
 
PDF
MuleSoft Anypoint Platformのコンセプトとサービス
Salesforce Developers Japan
 
PDF
Lightning時代のService Cloud概要とカスタマイズ
Salesforce Developers Japan
 
PPTX
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
Hormoz Tarevern
 
Easy No-Code Integrations with External Services and Visual Flow
Salesforce Developers
 
Webinar: Cut that Clutter! Maintain a Clean Org and Improve Productivity
Salesforce Admins
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
New from Salesforce Labs
Salesforce Admins
 
Introduction to Einstein Bots
Salesforce Developers
 
Spring '18 開発者向け新機能
Salesforce Developers Japan
 
Rollin' Out Lightnin' Ain't All That Frightenin' by Jon Barlow
Salesforce Admins
 
アドバンスドLightningコンポーネント:品質の高いコンポーネント開発のためのTips
Salesforce Developers Japan
 
Salesforce for Admins Keynote - Dreamforce 2016
Salesforce Admins
 
はじめようLightning Component開発
Salesforce Developers Japan
 
Dallas Salesforce User Group Meeting - March 2011 (Sponsored by Statera)
Kevin Richardson
 
#DF17Recap series: Make apps smarter with Einstein
Salesforce Developers
 
Webinar: 5 Game Changing Lightning Components on AppExchange
Salesforce Admins
 
Build Your Lightning Rollout Plan - September 2017
Salesforce Admins
 
Winter '19 開発者向け新機能
Salesforce Developers Japan
 
I Built in Lightning and I Liked It
Salesforce Admins
 
Salesforce Known Issues: The Lifecycle of a Bug
Salesforce Developers
 
MuleSoft Anypoint Platformのコンセプトとサービス
Salesforce Developers Japan
 
Lightning時代のService Cloud概要とカスタマイズ
Salesforce Developers Japan
 
Dreamforce 2014 - Salesforce Python SDK for REST/SOAP APIs
Hormoz Tarevern
 

Viewers also liked (20)

PDF
Carta despido 1
acobra
 
PPT
Aulas eletricista de manutençao
blogsopotencia
 
DOC
João e maria
Fernanda Aparecida Américo
 
PPTX
Natal blog
marianamandane
 
PPT
Livre arbitrio
Francisco Cordeiro
 
PPS
Deus do impossivel
Ulisses Costa
 
PPS
Como eram os_servicos_de_bordo
popfran
 
PPT
Literatura
Lolla Sttar
 
PDF
Plano de Patrocínio Coliseu EF 18 de Março
Marcos Paulo da Costa
 
PPTX
Bosque oceánico caducifolio
Xose Luis Lopez
 
PPTX
Modalidades
ana89tenorio
 
PPTX
Recursos naturais jassira nº10 8ºd
Eb 2/3 Avelar Brotero
 
PDF
Revisão Bibliográfica - Design & Inovação
DeDeus12
 
DOC
Atividade extraclasse (tema 2)
Magno Brito
 
PDF
LUCAS QUERE SER PALLASO
Carmela Rodríguez
 
DOCX
Control de asistencia toe
retalledo
 
PDF
Desafio Sênior 2012 - Circular 001
Grupo Escoteiro Padre Olímpio
 
PDF
JPA - Mini-Livro - Iniciação e Conceitos
Paulo Carvalho
 
PDF
Boletim bimba 29 06-2014 campanha - lares para cristo (1)
Debora Teixeira
 
PPT
Aplicação de software social: Podcast
Geovane Piccinin
 
Carta despido 1
acobra
 
Aulas eletricista de manutençao
blogsopotencia
 
Natal blog
marianamandane
 
Livre arbitrio
Francisco Cordeiro
 
Deus do impossivel
Ulisses Costa
 
Como eram os_servicos_de_bordo
popfran
 
Literatura
Lolla Sttar
 
Plano de Patrocínio Coliseu EF 18 de Março
Marcos Paulo da Costa
 
Bosque oceánico caducifolio
Xose Luis Lopez
 
Modalidades
ana89tenorio
 
Recursos naturais jassira nº10 8ºd
Eb 2/3 Avelar Brotero
 
Revisão Bibliográfica - Design & Inovação
DeDeus12
 
Atividade extraclasse (tema 2)
Magno Brito
 
LUCAS QUERE SER PALLASO
Carmela Rodríguez
 
Control de asistencia toe
retalledo
 
Desafio Sênior 2012 - Circular 001
Grupo Escoteiro Padre Olímpio
 
JPA - Mini-Livro - Iniciação e Conceitos
Paulo Carvalho
 
Boletim bimba 29 06-2014 campanha - lares para cristo (1)
Debora Teixeira
 
Aplicação de software social: Podcast
Geovane Piccinin
 
Ad

Similar to Intro to Apex Testing - Dreamforce 2016 (20)

PDF
Apex Testing Best Practices
Salesforce Developers
 
PPTX
Apex 10 commandments df14
Kevin Poorman
 
PPTX
Release Management: Managing Your Internal Releases
Joshua Hoskins
 
PPTX
Getting Started with Process Builder by Susan Sparks
Salesforce Admins
 
PDF
3 Ways to Increase Executive Adoption of Salesforce
Salesforce Admins
 
PPTX
Lightning Fast Tips For Your Lightning Roll Out by Kim Schaefges, Nicole Dams...
Salesforce Admins
 
PPTX
How to Optimize Your AppExchange Listing
Eric Wu
 
PDF
Five Developer Tips Every Admin Needs To Know
Salesforce Developers
 
PPT
Advanced Reporting and Dashboards for Executive Visibility
dreamforce2006
 
PDF
ISV Tech Talk: Environment Hub (Dreamforce 2015)
Salesforce Partners
 
PDF
DF15_ReviewTestGo
Debbie Paterick
 
PDF
Advanced Lightning Components
Salesforce Developers
 
PDF
Introduction to Apex Triggers
Salesforce Developers
 
PDF
The Apex Interactive Debugger
Salesforce Developers
 
PDF
Wave - Basics to Dashboard Video: http://tinyurl.com/oh25zfo
Deepa Patel
 
PPTX
Achieving Awesome Adoption Through Training & Support by Louise Lockie
Salesforce Admins
 
PDF
Review, Test and Go! - Deborah Paterick, Helen Lueck, Frank Montoya
Salesforce Admins
 
PPTX
Salesforce Data Tips, Tricks & Strategy (Dreamforce 15 Session)
NetStronghold
 
PDF
Manage Development in Your Org with Salesforce Governance Framework
Salesforce Developers
 
PDF
Commission Tracking: Automate Using Process Builder, Formulas and Workflows
Summa
 
Apex Testing Best Practices
Salesforce Developers
 
Apex 10 commandments df14
Kevin Poorman
 
Release Management: Managing Your Internal Releases
Joshua Hoskins
 
Getting Started with Process Builder by Susan Sparks
Salesforce Admins
 
3 Ways to Increase Executive Adoption of Salesforce
Salesforce Admins
 
Lightning Fast Tips For Your Lightning Roll Out by Kim Schaefges, Nicole Dams...
Salesforce Admins
 
How to Optimize Your AppExchange Listing
Eric Wu
 
Five Developer Tips Every Admin Needs To Know
Salesforce Developers
 
Advanced Reporting and Dashboards for Executive Visibility
dreamforce2006
 
ISV Tech Talk: Environment Hub (Dreamforce 2015)
Salesforce Partners
 
DF15_ReviewTestGo
Debbie Paterick
 
Advanced Lightning Components
Salesforce Developers
 
Introduction to Apex Triggers
Salesforce Developers
 
The Apex Interactive Debugger
Salesforce Developers
 
Wave - Basics to Dashboard Video: http://tinyurl.com/oh25zfo
Deepa Patel
 
Achieving Awesome Adoption Through Training & Support by Louise Lockie
Salesforce Admins
 
Review, Test and Go! - Deborah Paterick, Helen Lueck, Frank Montoya
Salesforce Admins
 
Salesforce Data Tips, Tricks & Strategy (Dreamforce 15 Session)
NetStronghold
 
Manage Development in Your Org with Salesforce Governance Framework
Salesforce Developers
 
Commission Tracking: Automate Using Process Builder, Formulas and Workflows
Summa
 
Ad

Recently uploaded (20)

PPTX
677697609-States-Research-Questions-Final.pptx
francistiin8
 
PPTX
Blended Family Future, the Mayflower and You
UCG NWA
 
PPTX
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
PPTX
Bob Stewart Humble Obedience 07-13-2025.pptx
FamilyWorshipCenterD
 
PDF
Medical Technology Corporation: Supply Chain Strategy
daretruong
 
PDF
What should be in a Leadership and Motivation Plan?
Writegenic AI
 
PPTX
AI presentation for everyone in every fields
dodinhkhai1
 
PPTX
some leadership theories MBA management.pptx
rkseo19
 
PDF
Generalization predition MOOCs - Conference presentation - eMOOCs 2025
pmmorenom01
 
PPTX
g1-oral-comm-1.pptx dkekekwkwoowowwkkrkrrkfkfkfm
hnanie845
 
PDF
Cloud Computing Service Availability.pdf
chakrirocky1
 
PPTX
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
PPTX
2025-07-13 Abraham 07 (shared slides).pptx
Dale Wells
 
PPTX
Food_and_Drink_Bahasa_Inggris_Kelas_5.pptx
debbystevani36
 
PDF
The Family Secret (essence of loveliness)
Favour Biodun
 
PDF
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
PPTX
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
PPTX
presentation on legal and regulatory action
raoharsh4122001
 
PPTX
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
PDF
FINAL ZAKROS - UNESCO SITE CANDICACY - PRESENTATION - September 2024
StavrosKefalas1
 
677697609-States-Research-Questions-Final.pptx
francistiin8
 
Blended Family Future, the Mayflower and You
UCG NWA
 
Presentationexpressions You are student leader and have just come from a stud...
BENSTARBEATZ
 
Bob Stewart Humble Obedience 07-13-2025.pptx
FamilyWorshipCenterD
 
Medical Technology Corporation: Supply Chain Strategy
daretruong
 
What should be in a Leadership and Motivation Plan?
Writegenic AI
 
AI presentation for everyone in every fields
dodinhkhai1
 
some leadership theories MBA management.pptx
rkseo19
 
Generalization predition MOOCs - Conference presentation - eMOOCs 2025
pmmorenom01
 
g1-oral-comm-1.pptx dkekekwkwoowowwkkrkrrkfkfkfm
hnanie845
 
Cloud Computing Service Availability.pdf
chakrirocky1
 
Inspired by VeinSense: Supercharge Your Hackathon with Agentic AI
ShubhamSharma2528
 
2025-07-13 Abraham 07 (shared slides).pptx
Dale Wells
 
Food_and_Drink_Bahasa_Inggris_Kelas_5.pptx
debbystevani36
 
The Family Secret (essence of loveliness)
Favour Biodun
 
Leveraging the Power of Jira Dashboard.pdf
siddharthshukla742740
 
BARRIERS TO EFFECTIVE COMMUNICATION.pptx
shraddham25
 
presentation on legal and regulatory action
raoharsh4122001
 
Pastor Bob Stewart Acts 21 07 09 2025.pptx
FamilyWorshipCenterD
 
FINAL ZAKROS - UNESCO SITE CANDICACY - PRESENTATION - September 2024
StavrosKefalas1
 

Intro to Apex Testing - Dreamforce 2016

  • 1. Introduction to Apex Testing [email protected] @meerkatz [email protected] Laura Meerkatz Developer Salesforce.org Adam Lincoln Developer Salesforce.org
  • 2. Forward-Looking Statements 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. Agenda Why do we write tests? What to test Best practices Resources Q&A 1 2 3 4 5
  • 5. Why do we test?
  • 7. What goes into each test class Test Structure
  • 9. What to test Things that should happen do happen (positive) Things that shouldn’t happen don’t happen (negative) User access Exceptions Bulk testing 1 2 3 4 5
  • 10. Calculate employee bonuses Sample scenario • Employees are awarded a 1% bonus based on the amount of closed won opportunities they own • The maximum bonus is $25,000 • Only admins can retotal bonuses • A negative total opportunity amount should result in an exception
  • 11. Verify that the things that should happen do happen Positive Tests
  • 12. Verify that the things that should happen do happen Positive Tests
  • 13. Verify that the things that should not happen don’t happen Negative Tests
  • 14. Verify that the things that should not happen don’t happen Negative Tests
  • 15. Verify that users can’t do things they don’t have permission to do Use System.runAs() to test user access
  • 16. Verify when your code should be throwing an exception Exception Testing
  • 17. Verify that your code will work when several records are updated at once Bulk Testing
  • 20. Sometimes you have to use SeeAllData=true There are exceptions
  • 21. Set up your test data in one place so you can reuse it everywhere Use Test Data Factories
  • 22. Set up test data for all methods in one place Use @TestSetup
  • 23. Reset governor limits Use Test.startTest()/Test.stopTest()
  • 25. Summary • Tests help you sleep better at night! • Test for things that should happen and things that shouldn’t happen • Use test data factories and @TestSetup to make creating test data easy • Use developer console to run individual tests and see coverage

Editor's Notes

  • #3: Key Takeaway: We are a publicly traded company. Please make your buying decisions only on the products commercially available from Salesforce. Talk Track: Before I begin, just a quick note that when considering future developments, whether by us or with any other solution provider, you should always base your purchasing decisions on what is currently available.
  • #5: Who here is an Apex dev? Who here has written Apex tests? Who feels like they’re writing good tests?
  • #9: Positive Negative Access Exception Bulk
  • #11: For our sample code, we’re testing to see that employees are awarded a certain amount based on the amount of closed won opportunities they own.
  • #20: Off by default Makes assertions easier Avoid row lock exceptions Makes tests run faster
  • #21: By default SeeAllData is false. When SeeAllData is set to true, test methods have access to all data in the organization. This can lead to row lock errors that prevent users from updating records because those records are currently being accessed in tests.
  • #22: Also: Use Test.loadData() to load data from csvs stored as static resources
  • #23: Runs once before all test methods Changes roll back between tests
  • #24: Also forces async calls to run sychronously
  • #25: demo