SlideShare a Scribd company logo
Test Classes - Salesforce
LEARN . SHARE . CELEBRATE . SALESFORCE
Why Test Classes
• Error-free code
• Check whether code is working as expected or not
• Deploy Apex to a production environment
• Salesforce requires at least 75% of your code to be covered by
our test classes
• Cover each positive and negative use case of your code
Code Coverage Calculation
• Code coverage is calculated by dividing the number of unique
Apex code lines executed during your test method execution by
the total number of Apex code lines in all of your trigger and
classes.
(Note: these numbers do not include lines of code within your
testMethods)
Considerations
• System.debug are not part of Apex code coverage.
• Test methods and test classes are not counted as part of Apex
code limit.
• Every trigger you are trying to deploy should have at least 1%
coverage
• Class can be deployed on 0% coverage but yes overall coverage
of your production org after getting your code deployed should be
75%, otherwise Salesforce won’t let you deploy your code.
• Strive for 100% code coverage. Do not focus on the 75%
requirement.
• Test methods do not expect any Id or rely upon a specific data
set. Test method will fail when deploy to other organisation.
• System.assertEquals
Test Method Syntax and Static Methods
• Static testMethod keyword
• @IsTest : Define classes that only contain code used for testing your
application
• Test.isRunningTest() : Returns true if the currently executing code was called
by code contained in a test method, false otherwise
• Test.startTest : Test actually begins. Initialize variables, setup data before it.
Get a fresh set of governor limits for the remainder of the test until you call
Test.stopTest
• System.RunAs : Change user contexts to either an existing user or a new user.
All of that user's record sharing is then enforced
• isTest(SeeAllData = true) : Use on class methods in exceptional cases where
there are sObjects that doesn't allow DML operation e.g. PriceBook creation
Example
@isTest
private class MyTestClass {
@isTest static void test1(){
// Implement test code
}
}
Questions
Follow Seema Dhingra
Seema Dhingra
Associate Manager Accenture
Blog : https://salesforcecodelearn.blogsopt.in
Twitter : @sfdc_Seema
Facebook Page : @salesforcecodelearn

More Related Content

What's hot

Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
Vivek Chawla
 
Salesforce Lightning Process builder
Salesforce Lightning Process builderSalesforce Lightning Process builder
Salesforce Lightning Process builder
Thinqloud
 
Dynamic input tables lwc vs aura vs. visualforce
Dynamic input tables  lwc vs aura vs. visualforceDynamic input tables  lwc vs aura vs. visualforce
Dynamic input tables lwc vs aura vs. visualforce
Mike Tetlow
 
Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015
Samuel De Rycke
 
Getting Started With Apex REST Services
Getting Started With Apex REST ServicesGetting Started With Apex REST Services
Getting Started With Apex REST Services
Salesforce Developers
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
Pekka Klärck
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security Model
Salesforce Developers
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetup
MuleSoft Meetup
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
Jitendra Zaa
 
Anypoint API Manager Custom Policies & Best Practices
Anypoint API Manager Custom Policies & Best PracticesAnypoint API Manager Custom Policies & Best Practices
Anypoint API Manager Custom Policies & Best Practices
MuleSoft Meetups
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | Edureka
Edureka!
 
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Developers
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
Hitesh-Java
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component
SmritiSharan1
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
Anuraj S.L
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Edureka!
 
Salesforce talk
Salesforce talkSalesforce talk
Salesforce talk
Suvendu Roy
 
Deep Dive into Apex Triggers
Deep Dive into Apex TriggersDeep Dive into Apex Triggers
Deep Dive into Apex Triggers
Salesforce Developers
 
Choosing the Right Demo Environment (Salesforce Partners)
Choosing the Right Demo Environment (Salesforce Partners)Choosing the Right Demo Environment (Salesforce Partners)
Choosing the Right Demo Environment (Salesforce Partners)
Salesforce Partners
 

What's hot (20)

Salesforce Development Best Practices
Salesforce Development Best PracticesSalesforce Development Best Practices
Salesforce Development Best Practices
 
Salesforce Lightning Process builder
Salesforce Lightning Process builderSalesforce Lightning Process builder
Salesforce Lightning Process builder
 
Dynamic input tables lwc vs aura vs. visualforce
Dynamic input tables  lwc vs aura vs. visualforceDynamic input tables  lwc vs aura vs. visualforce
Dynamic input tables lwc vs aura vs. visualforce
 
Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015Asynchronous Apex Salesforce World Tour Paris 2015
Asynchronous Apex Salesforce World Tour Paris 2015
 
Getting Started With Apex REST Services
Getting Started With Apex REST ServicesGetting Started With Apex REST Services
Getting Started With Apex REST Services
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
Introduction to the Salesforce Security Model
Introduction to the Salesforce Security ModelIntroduction to the Salesforce Security Model
Introduction to the Salesforce Security Model
 
Salesforce integration best practices columbus meetup
Salesforce integration best practices   columbus meetupSalesforce integration best practices   columbus meetup
Salesforce integration best practices columbus meetup
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Anypoint API Manager Custom Policies & Best Practices
Anypoint API Manager Custom Policies & Best PracticesAnypoint API Manager Custom Policies & Best Practices
Anypoint API Manager Custom Policies & Best Practices
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | Edureka
 
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for Deployment
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 
Introduction to Lightning Web Component
Introduction to Lightning Web Component Introduction to Lightning Web Component
Introduction to Lightning Web Component
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An Introduction
 
An overview of selenium webdriver
An overview of selenium webdriverAn overview of selenium webdriver
An overview of selenium webdriver
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
Salesforce talk
Salesforce talkSalesforce talk
Salesforce talk
 
Deep Dive into Apex Triggers
Deep Dive into Apex TriggersDeep Dive into Apex Triggers
Deep Dive into Apex Triggers
 
Choosing the Right Demo Environment (Salesforce Partners)
Choosing the Right Demo Environment (Salesforce Partners)Choosing the Right Demo Environment (Salesforce Partners)
Choosing the Right Demo Environment (Salesforce Partners)
 

Similar to Test Classes in Salesforce

Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
Chamil Madusanka
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
Jitendra Zaa
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
Ram Awadh Prasad, PMP
 
An introduction to apex code test methods developer.force
An introduction to apex code test methods   developer.forceAn introduction to apex code test methods   developer.force
An introduction to apex code test methods developer.force
sendmail2cherukuri
 
Testclass [Autosaved]
Testclass [Autosaved]Testclass [Autosaved]
Testclass [Autosaved]Suraj Singh
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
AgileNetwork
 
Code coverage
Code coverageCode coverage
Code coverage
Return on Intelligence
 
Database Unit Testing Made Easy with VSTS
Database Unit Testing Made Easy with VSTSDatabase Unit Testing Made Easy with VSTS
Database Unit Testing Made Easy with VSTS
Sanil Mhatre
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
SumitKumar918321
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best Practises
Sebastian Wagner
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Aleksandar Bozinovski
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
Aleksandar Bozinovski
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
Aktuğ Urun
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
Roman Okolovich
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approach
Enrico Da Ros
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
Testing Frameworks
Testing FrameworksTesting Frameworks
Testing Frameworks
Moataz Nabil
 

Similar to Test Classes in Salesforce (20)

Unit testing in Force.com platform
Unit testing in Force.com platformUnit testing in Force.com platform
Unit testing in Force.com platform
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 
An introduction to apex code test methods developer.force
An introduction to apex code test methods   developer.forceAn introduction to apex code test methods   developer.force
An introduction to apex code test methods developer.force
 
Testclass [Autosaved]
Testclass [Autosaved]Testclass [Autosaved]
Testclass [Autosaved]
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...Agile Mumbai 2020 Conference |  How to get the best ROI on Your Test Automati...
Agile Mumbai 2020 Conference | How to get the best ROI on Your Test Automati...
 
Junit
JunitJunit
Junit
 
Code coverage
Code coverageCode coverage
Code coverage
 
Database Unit Testing Made Easy with VSTS
Database Unit Testing Made Easy with VSTSDatabase Unit Testing Made Easy with VSTS
Database Unit Testing Made Easy with VSTS
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
SF1 - Apex Development Best Practises
SF1 - Apex Development Best PractisesSF1 - Apex Development Best Practises
SF1 - Apex Development Best Practises
 
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable CodeMicrosoft Fakes, Unit Testing the (almost) Untestable Code
Microsoft Fakes, Unit Testing the (almost) Untestable Code
 
Unit Tests with Microsoft Fakes
Unit Tests with Microsoft FakesUnit Tests with Microsoft Fakes
Unit Tests with Microsoft Fakes
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Testing, a pragmatic approach
Testing, a pragmatic approachTesting, a pragmatic approach
Testing, a pragmatic approach
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Testing Frameworks
Testing FrameworksTesting Frameworks
Testing Frameworks
 

More from Atul Gupta(8X)

Developer Week 2019 Delhi + Spring 19 Features
Developer Week 2019 Delhi + Spring 19 FeaturesDeveloper Week 2019 Delhi + Spring 19 Features
Developer Week 2019 Delhi + Spring 19 Features
Atul Gupta(8X)
 
Engagement Studio, Pardot at Developer Week 2019
Engagement Studio, Pardot at Developer Week 2019Engagement Studio, Pardot at Developer Week 2019
Engagement Studio, Pardot at Developer Week 2019
Atul Gupta(8X)
 
Dreamforce 2018 Global Gathering
Dreamforce 2018 Global Gathering Dreamforce 2018 Global Gathering
Dreamforce 2018 Global Gathering
Atul Gupta(8X)
 
Introduction to Salesforce UI API
Introduction to Salesforce UI APIIntroduction to Salesforce UI API
Introduction to Salesforce UI API
Atul Gupta(8X)
 
TrailheaDX Global Gathering: Agenda and Introduction
TrailheaDX Global Gathering: Agenda and IntroductionTrailheaDX Global Gathering: Agenda and Introduction
TrailheaDX Global Gathering: Agenda and Introduction
Atul Gupta(8X)
 
Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...
Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...
Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...
Atul Gupta(8X)
 
Virtual #SalesforceSaturday : Salesforce Connect with Cross Org Adaptor
Virtual #SalesforceSaturday : Salesforce Connect with Cross Org AdaptorVirtual #SalesforceSaturday : Salesforce Connect with Cross Org Adaptor
Virtual #SalesforceSaturday : Salesforce Connect with Cross Org Adaptor
Atul Gupta(8X)
 
#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained
Atul Gupta(8X)
 
#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri
#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri
#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri
Atul Gupta(8X)
 
Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...
Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...
Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...
Atul Gupta(8X)
 
Dreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WIT
Dreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WITDreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WIT
Dreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WIT
Atul Gupta(8X)
 
Developer to Consultant : Transformation Tips #SalesforceSaturday
Developer to Consultant : Transformation Tips #SalesforceSaturdayDeveloper to Consultant : Transformation Tips #SalesforceSaturday
Developer to Consultant : Transformation Tips #SalesforceSaturday
Atul Gupta(8X)
 
Spring 17 Salesforce Viewing Party : New Delhi Salesforce Developer Group
Spring 17 Salesforce Viewing Party : New Delhi Salesforce Developer GroupSpring 17 Salesforce Viewing Party : New Delhi Salesforce Developer Group
Spring 17 Salesforce Viewing Party : New Delhi Salesforce Developer Group
Atul Gupta(8X)
 
Meetup with kavindra : New Delhi Salesforce Developer Group
Meetup with kavindra : New Delhi Salesforce Developer GroupMeetup with kavindra : New Delhi Salesforce Developer Group
Meetup with kavindra : New Delhi Salesforce Developer Group
Atul Gupta(8X)
 
Marketing Cloud, SalesforceSaturday
Marketing Cloud, SalesforceSaturdayMarketing Cloud, SalesforceSaturday
Marketing Cloud, SalesforceSaturday
Atul Gupta(8X)
 
Live Agent Setup SalesforceSaturday
Live Agent Setup SalesforceSaturdayLive Agent Setup SalesforceSaturday
Live Agent Setup SalesforceSaturday
Atul Gupta(8X)
 
Data Loader Command Line Interface
Data Loader Command Line InterfaceData Loader Command Line Interface
Data Loader Command Line Interface
Atul Gupta(8X)
 
How to list your app on AppExchange
How to list your app on AppExchangeHow to list your app on AppExchange
How to list your app on AppExchange
Atul Gupta(8X)
 
Force.com Migration Tool
Force.com Migration ToolForce.com Migration Tool
Force.com Migration Tool
Atul Gupta(8X)
 
TrailheaDX Viewing Party - New Delhi Salesforce DG
TrailheaDX Viewing Party - New Delhi Salesforce DGTrailheaDX Viewing Party - New Delhi Salesforce DG
TrailheaDX Viewing Party - New Delhi Salesforce DG
Atul Gupta(8X)
 

More from Atul Gupta(8X) (20)

Developer Week 2019 Delhi + Spring 19 Features
Developer Week 2019 Delhi + Spring 19 FeaturesDeveloper Week 2019 Delhi + Spring 19 Features
Developer Week 2019 Delhi + Spring 19 Features
 
Engagement Studio, Pardot at Developer Week 2019
Engagement Studio, Pardot at Developer Week 2019Engagement Studio, Pardot at Developer Week 2019
Engagement Studio, Pardot at Developer Week 2019
 
Dreamforce 2018 Global Gathering
Dreamforce 2018 Global Gathering Dreamforce 2018 Global Gathering
Dreamforce 2018 Global Gathering
 
Introduction to Salesforce UI API
Introduction to Salesforce UI APIIntroduction to Salesforce UI API
Introduction to Salesforce UI API
 
TrailheaDX Global Gathering: Agenda and Introduction
TrailheaDX Global Gathering: Agenda and IntroductionTrailheaDX Global Gathering: Agenda and Introduction
TrailheaDX Global Gathering: Agenda and Introduction
 
Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...
Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...
Building Next-Gen Communities With Lightning Series : Session#01 : Virtual #S...
 
Virtual #SalesforceSaturday : Salesforce Connect with Cross Org Adaptor
Virtual #SalesforceSaturday : Salesforce Connect with Cross Org AdaptorVirtual #SalesforceSaturday : Salesforce Connect with Cross Org Adaptor
Virtual #SalesforceSaturday : Salesforce Connect with Cross Org Adaptor
 
#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained#SalesforceSaturday : Salesforce BIG Objects Explained
#SalesforceSaturday : Salesforce BIG Objects Explained
 
#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri
#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri
#SalesforceSaturday Spring18 Release Highlights by Manish Thaduri
 
Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...
Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...
Success Story and Dreamforce Experience : Jaipur User Group DF17 Global Gathe...
 
Dreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WIT
Dreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WITDreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WIT
Dreamforce Global Gathering : New Delhi Salesforce DG & Gurgaon WIT
 
Developer to Consultant : Transformation Tips #SalesforceSaturday
Developer to Consultant : Transformation Tips #SalesforceSaturdayDeveloper to Consultant : Transformation Tips #SalesforceSaturday
Developer to Consultant : Transformation Tips #SalesforceSaturday
 
Spring 17 Salesforce Viewing Party : New Delhi Salesforce Developer Group
Spring 17 Salesforce Viewing Party : New Delhi Salesforce Developer GroupSpring 17 Salesforce Viewing Party : New Delhi Salesforce Developer Group
Spring 17 Salesforce Viewing Party : New Delhi Salesforce Developer Group
 
Meetup with kavindra : New Delhi Salesforce Developer Group
Meetup with kavindra : New Delhi Salesforce Developer GroupMeetup with kavindra : New Delhi Salesforce Developer Group
Meetup with kavindra : New Delhi Salesforce Developer Group
 
Marketing Cloud, SalesforceSaturday
Marketing Cloud, SalesforceSaturdayMarketing Cloud, SalesforceSaturday
Marketing Cloud, SalesforceSaturday
 
Live Agent Setup SalesforceSaturday
Live Agent Setup SalesforceSaturdayLive Agent Setup SalesforceSaturday
Live Agent Setup SalesforceSaturday
 
Data Loader Command Line Interface
Data Loader Command Line InterfaceData Loader Command Line Interface
Data Loader Command Line Interface
 
How to list your app on AppExchange
How to list your app on AppExchangeHow to list your app on AppExchange
How to list your app on AppExchange
 
Force.com Migration Tool
Force.com Migration ToolForce.com Migration Tool
Force.com Migration Tool
 
TrailheaDX Viewing Party - New Delhi Salesforce DG
TrailheaDX Viewing Party - New Delhi Salesforce DGTrailheaDX Viewing Party - New Delhi Salesforce DG
TrailheaDX Viewing Party - New Delhi Salesforce DG
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
vrstrong314
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
abdulrafaychaudhry
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Game Development with Unity3D (Game Development lecture 3)
Game Development  with Unity3D (Game Development lecture 3)Game Development  with Unity3D (Game Development lecture 3)
Game Development with Unity3D (Game Development lecture 3)
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 

Test Classes in Salesforce

  • 1. Test Classes - Salesforce LEARN . SHARE . CELEBRATE . SALESFORCE
  • 2. Why Test Classes • Error-free code • Check whether code is working as expected or not • Deploy Apex to a production environment • Salesforce requires at least 75% of your code to be covered by our test classes • Cover each positive and negative use case of your code
  • 3. Code Coverage Calculation • Code coverage is calculated by dividing the number of unique Apex code lines executed during your test method execution by the total number of Apex code lines in all of your trigger and classes. (Note: these numbers do not include lines of code within your testMethods)
  • 4. Considerations • System.debug are not part of Apex code coverage. • Test methods and test classes are not counted as part of Apex code limit. • Every trigger you are trying to deploy should have at least 1% coverage • Class can be deployed on 0% coverage but yes overall coverage of your production org after getting your code deployed should be 75%, otherwise Salesforce won’t let you deploy your code. • Strive for 100% code coverage. Do not focus on the 75% requirement. • Test methods do not expect any Id or rely upon a specific data set. Test method will fail when deploy to other organisation. • System.assertEquals
  • 5. Test Method Syntax and Static Methods • Static testMethod keyword • @IsTest : Define classes that only contain code used for testing your application • Test.isRunningTest() : Returns true if the currently executing code was called by code contained in a test method, false otherwise • Test.startTest : Test actually begins. Initialize variables, setup data before it. Get a fresh set of governor limits for the remainder of the test until you call Test.stopTest • System.RunAs : Change user contexts to either an existing user or a new user. All of that user's record sharing is then enforced • isTest(SeeAllData = true) : Use on class methods in exceptional cases where there are sObjects that doesn't allow DML operation e.g. PriceBook creation
  • 6. Example @isTest private class MyTestClass { @isTest static void test1(){ // Implement test code } }
  • 8. Follow Seema Dhingra Seema Dhingra Associate Manager Accenture Blog : https://salesforcecodelearn.blogsopt.in Twitter : @sfdc_Seema Facebook Page : @salesforcecodelearn