Testing, Debugging, and Deployment
Testing, Debugging, and Deployment
Write and execute tests for triggers, controllers, classes, flows, and
processes using various sources of test data.
1
○ All tests can be run by selecting ‘Run All’ from the ‘Test’ menu item in the
Developer Console
○ It is also possible to run all tests by clicking the ‘Run All Tests’ button on the
‘Apex Classes’ page in Setup.
2
○ Test classes can be run using the Apex Test Execution page in Setup and the
testing options available in the Developer console
○ Tests can also be executed using Salesforce Extensions for Visual Studio
Code, Code Builder, and APIs such as the SOAP API and Tooling Rest API.
○ Apex test classes and specific test methods can be executed in the Developer
Console, Setup, Visual Studio Code, Code Builder, and when using an API
such as the SOAP API.
● Skip Code Coverage Information
○ The option to skip code coverage is available when a new test is run in the
Developer Console by selecting the ‘New Run’ option from the ‘Test’ menu.
■ The ‘Setting’ button can be clicked to specify whether code coverage
should be skipped.
3
○ It is also possible to select this option on the ‘Apex Test Execution’ page in
Setup while selecting the test classes for a test run.
4
○ Test.loadData()
■ Call Test.loadData() within the test method, passion the sObject type
token and the static resource name as the parameters.
○ The suite manager is used to create or delete test suites or edit which classes
a particular test suite contains,
○ A test suite is a collection of Apex test classes that are run together. The new
suite option is used to group test classes that are run together. It cannot be
used to create a test class.
5
○ The Developer Console runs tests asynchronously by default. Tests are run
synchronously only when there is only one test class being run and the
[Always Run Asynchronously] option is not checked.
○ If multiple test classes are run, the test will always be run asynchronously
whether or not the [Always Run Asynchronously] option is checked.
● Using Limits, startTest, and stopTest
○ The Test.startTest() and Test.stopTest() methods can be used with the Limits
methods(Such as Limits.getDMLStatements(), Limits.getQueries(). etc.) to
determine the amount of governed resources that have been consumed in a
specific block of code.
○ Test.startTest()
■ Marks the point in the test code when the test actually begins
○ Test.stopTest()
■ Marks the point in the test code when the test ends.
○ Any code that executes after the call to Test.startTest() and before
Test.stopTest() is assigned a new set of governor limits which will ignore any
DML or queries done outside of the start and stop testing.
■ It will only count what happens in between as part of the test.
■
6
● Error methods for testing Apex code
○ AddError()
○ hasErrors()
○ getErrors()
○ The system method runAs() enables test methods to be written that change
the user context to an existing user or a new user so that the user’s record
sharing is enforced.
○ The runAs() method does not enforce user permissions or field-level
permissions, only record sharing.
7
○ New users can be created with runAs() even if the organization has no
additional user licenses.
8
○ The ‘Executed Units’ tab under the ‘Execution Overview’ log panel provides
several metrics, including the execution time (total, average, minimum, and
maximum), for any item that is captured in the debug log.
○ The ‘Stack Tree’ and ‘Execution Stack’ can only display the total execution
time.
○
● Troubleshoot Processes with Apex Debug Logs
○ Record change processes in Process Builder are fired when a record is
updated that meets the defined criteria.
○ While ‘myVariable_current’ in the debug log contains all of the record’s
current field values,
○ ‘myVariable_old’ contains all the field values before the record was updated.
○ These information can then be used to determine whether the records are
updated accordingly to meet the criteria required by the processes.
9
○
● Debug Log
○ The debug log does not include information from actions triggered by
time-based workflows.
○ A debug log can record
■ database operations
■ System processes
■ And errors that occur when executing a transaction or Running unit
tests
○ Debug logs can contain information about
■ Database changes
■ HTTP callouts
■ Apex errors
■ Resources used by Apex
■ Automated workflow processes
● Workflow rules
● Assignment rules
● Approval processes
● Validation rules
○ Debug log categories
10
○ Only helpful when apex code is involved.
● Callout,
● Database,
● System,
● Validation,
● Visualfoce,
● Workflow.
■
● Debug Log
○ A debug log has the following sections:
■ The header
● Contains the version of the API used during the transaction
● The log category
11
● Level used to generate the log
■ Log levels available in Apex are (Listed from Lowest to highest)
12
● None
● Error
● Warn
● Info
● Debug
● Fine
● Finer
● Finest
13
■
○ Debug logs are automatically deleted after a certain period depending on
their type.
○ The ‘View All Data’ permission is what is required in order to access debug
logs.
● Managing Perspectives in the Log Inspector
○ Developers may create a custom perspective or modify an existing
perspective. In the Developer Console > Log Inspector > Debug > View Log
Panels > Select the panels you want to include in the perspective. If you
modify a perspective, an * is appended to the perspective name until it is
saved. And, to change the default perspective, Perspective name > Set
Default.
● Checkpoint Inspector
○ The Checkpoint Inspector has 2 tabs
■ Heap
● Types
○ It shows the objects that were instantiated and the
memory consumed in bytes.
● Instance
○ It shows the instances of a particular object type
● State
○ It shows the object’s fields and values at a particular
checkpoint
14
■ Symbols
● Displays all symbols in memory at a checkpoint using a tree
view.
Given a scenario, know how and when to use the Salesforce Developer
tools such as Salesforce DX, Salesforce CLI, and Developer Console.
15
● Anonymous Blocks
○ Like in a regular transaction, data changes made in an anonymous block will
be committed to the database.
○ Anonymous blocks always run as the current user.
○ Anonymous blocks can be compiled and executed using the Developer
Console, Visual Studio Code, Code Builder, or via a SOAP API call.
○ The Tooling API can also be used to execute anonymous block via REST calls.
● How Salesforce Developer Experience (DX) Tooling Changes the Way You
Work
○ Salesforce DX involves the use ofSalesforce CLItomigrate code and
metadata between orgs, and generate scratch orgs, which serve as personal
development environments for developers and packages or updates
○ Aversion control systemis used to manage and trackchanges
■ With code and metadata hosted in a code repository, Salesforce CLI
can effectively be used to implement continuous integration and
continuous deployments.
○ By using theSalesfroce Extensions Packfor VisualStudio Code, a developer
can easily set up a Salesfroce DX project, perform Salesforce CLI commands
among several other integrated features, and build Lightning Components,
Apex, and Visualforce in the editor. Code Builder, which is a web-based
integrated development environment, possesses the capabilities to Visual
Studio Code, Salesforce extensions, and Salesforce CLI and can also be used
in developing Salesforce applications using Salesforce DX.
16
○
○ The Developer Console, a web-based IDE that is connected to only one org
would not be ideally involved in the development process of a Salesforce DX
project. Since Salesforce CLI is already used to migrate metadata between
orgs, using change set is not considered part of the application lifecycle in
Salesforce DX.
● Checkpoints Tab
○ The Checkpoints tab in the Developer Console provides the following
information:
■ Namespace, Class, Line, and Time(DateTime).
○
17
Describe the environments, requirements, and process for deploying
code and associated configurations
■ Only full sandboxes support performance testing, load testing, and
staging
18
■ A full sandbox is a replica of the production org, including all data,
such as object records and attachments, and metadata.
■ The length of the refresh interval makes it difficult to use Full
sandboxes for development.
■ Used for quality assurance tasks, such as user acceptance testing,
integration testing, and training.
■ However, Developer Pro sandboxes can also be used for QA tasks.
○ NOTE:
■ Developer Pro and Partial Copy sandbox orgs cannot be used to
publish apps in AppExchange.
○ An Enterprise Developer Edition or Scratch Pro org does not exist.
○ ATrial Production orgis a trial version of the productionorg and comes
with sample data and features based on the org edition to allow customers
to try out and evaluate the platform before subscribing.
19
○ Sandbox org- a nearly identical copy of the production org
○ Developer org- a Developer Edition org which is acopy of the Enterprise
Edition org but with limited storage and users.
○
20