Unit 1: Get A Refresh On Testing: Learning Objectives

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Platform Developer I Certification Prep: Testing, Debugging and Deployment

Unit 1: Get a Refresh on Testing


Learning Objectives
After completing this unit, you'll be able to:
• Describe the use cases for invoking anonymous code and the differences between invoking
Apex in execute anonymous vs. unit tests.
• Write and execute tests for triggers, controllers, classes, flows, and processes using various
sources of test data.

Key Topics
This unit prepares you for the Testing, Debugging, and Deployment section of the Platform Developer I exam,
which makes up 17% of the overall exam. This section of the exam tests these topics.

• Testing frameworks and requirements


• Test data
• Executing a test
• Test considerations

This unit provides a number of interactive, real-world, scenario-based questions that are a lot like the ones you
can encounter as a Salesforce developer. Looking at these scenarios helps prepare you to take the testing
section of the Platform Developer I exam. As you tackle the practice questions, you get immediate feedback on
your answers, along with detailed information on why your answers are correct (or incorrect).

The unit also contains interactive flashcards to help you prepare for this section of the exam.

Download the Guide


Would you like a hard copy of the contents in these modules? Each module includes a link to a printable
version you can download. Download the Platform Developer I Certification Prep: Testing, Debugging and
Deployment guide.

Exam Practice Questions


Ready to jump in? The sample tool below is not scored—it’s just an easy way to quiz yourself. To use it, read
the scenario and click the answer you think is correct. Some questions may have more than one correct
answer. Click Submit and you get a popup telling you whether the answer you chose is correct or incorrect,
and why; if there’s a longer explanation, click and then click anywhere in the window to close it. When you
reach the end you can review the answers or retake the questions.

1
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 1

A developer creates a new Visualforce page and Apex extension, and writes test classes that exercise 95%
coverage of the new Apex extension. Change set deployment to production fails with the test coverage
warning: "Average test coverage across all Apex classes and triggers is 74%, at least 75% test coverage is
required." What can the developer do to successfully deploy the new Visualforce page and extension?

ANSWER FEEDBACK

A. CREATE TEST CLASSES TO EXERCISE Incorrect. Test classes can cover only Apex classes, not
THE VISUALFORCE PAGE MARKUP. Visualforce pages.

B. SELECT FAST DEPLOYMENT TO Incorrect. The correct wording is “quick deployment”, but
BYPASS RUNNING ALL THE TESTS. the developer still wants to make sure all tests pass, so
running a quick deployment is not enough.

C. SELECT 'DISABLE PARALLEL APEX Incorrect. Disabling parallel Apex testing does not change
TESTING' TO RUN ALL THE TESTS. the 75% code coverage requirement.

D. ADD TEST METHODS TO EXISTING Correct. This increases the code coverage on the rest
TEST CLASSES FROM PREVIOUS of the Apex classes in the org.
DEPLOYMENTS.

2
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 2

Which is an accurate statement about creating unit tests in Apex?

ANSWER FEEDBACK

A. INCREASED TEST COVERAGE REQUIRES Incorrect. The number of lines of code in the test
LARGE TEST CLASSES WITH MANY LINES OF class does not matter, what matters is the amount
CODE IN ONE METHOD. of lines that the unit test covers.

B. TRIGGERS DO NOT REQUIRE ANY UNIT Incorrect. Triggers need to be covered by unit tests
TESTS IN ORDER FOR YOU TO DEPLOY THEM as well in order to be deployed.
FROM SANDBOX TO PRODUCTION.

C. UNIT TESTS WITH MULTIPLE METHODS Incorrect. When one method fails, the other test
RESULT IN ALL METHODS FAILING WHEN ONE methods can still succeed.
METHOD FAILS.

D. SYSTEM ASSERT STATEMENTS THAT DO Correct. Tests should assert your application’s
NOT INCREASE CODE COVERAGE CONTRIBUTE behavior to ensure quality of code and verify
IMPORTANT FEEDBACK IN UNIT TESTS. expected results.

3
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 3

What is the proper process for an Apex unit test?

ANSWER FEEDBACK

A. CREATE DATA FOR TESTING. CALL THE Correct. Creating your own data makes the
METHOD BEING TESTED. VERIFY THAT THE method independent of the data in your org.
RESULTS ARE CORRECT. Doing this helps to avoid errors when moving
your code from one org to another. To verify
that the method works as expected call it
using different inputs based on the data that
was created.

B. QUERY FOR TEST DATA USING Incorrect. SeeAllData=true should only be used in
SEEALLDATA=TRUE. CALL THE METHOD BEING specific scenarios when the data cannot be
TESTED. VERIFY THAT THE RESULTS ARE created on the test class.
CORRECT.

C. CREATE DATA FOR TESTING. EXECUTE Incorrect. unAllTests() executes all the methods in
RUNALLTESTS(). VERIFY THAT THE RESULTS the test class.
ARE CORRECT.

D. QUERY FOR TEST DATA USING Incorrect. SeeAllData=true should only be used in
SEEALLDATA=TRUE. EXECUTE RUNALLTESTS(). specific scenarios when the data cannot be
VERIFY THAT THE RESULTS ARE CORRECT. created on the test class.

4
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 4

A developer has a single custom controller class that works with a Visualforce wizard to support creating and
editing multiple sObjects. The wizard accepts data from user inputs across multiple Visualforce pages and from
a parameter on the initial URL. Which three statements are necessary inside the unit test for the custom
controller?

ANSWER FEEDBACK

A. TEST.SETCURRENTPAGE(PAGEREF); Correct. You need to set the


current page to make sure you
get the initial URL parameter.

B. STRING NEXTPAGE = CONTROLLER.SAVE().GETURL(); Correct. This statement


instantiates a new controller with
all parameters in the page.

C. Correct. This line is used to


APEXPAGES.CURRENTPAGE().GETPARAMETERS().PUT('INPUT', inject the query parameter
'TESTVALUE'); ?input=TestValue in the URL
for the page.

D. PUBLIC Incorrect. This is the declaration of


EXTENDEDCONTROLLER(APEXPAGES.STANDARDCONTROLLER the constructor for a controller
CNTRL) { } extension. This is not needed in the
test class.

5
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 5

An org has different Apex classes that provide account-related functionality. After a new validation rule is
added to the Account object, many of the test methods fail. Which two actions will resolve the failures and
reduce the number of code changes needed for future validation rules? (Select two answers.)

ANSWER FEEDBACK

A. CREATE A METHOD THAT CREATES VALID Correct. In test classes, the developer needs
ACCOUNT RECORDS, AND CALL THIS METHOD to first create the test records.
FROM WITHIN TEST METHODS.

B. CREATE A METHOD THAT QUERIES FOR VALID Incorrect. The developer needs to create the test
ACCOUNT RECORDS, AND CALL THIS METHOD records before querying them.
FROM WITHIN TEST METHODS.

C. CREATE A METHOD THAT LOADS VALID Correct. In test classes, the developer needs
ACCOUNT RECORDS FROM A STATIC to first populate the test records.
RESOURCE, AND CALL THIS METHOD WITHIN
TEST METHODS.

D. CREATE A METHOD THAT PERFORMS A Incorrect. The developer needs to create the test
CALLOUT FOR A VALID ACCOUNT RECORD, AND records before validating them.
CALL THIS METHOD FROM WITHIN TEST
METHODS.

6
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 6

When working in a sandbox environment, which two things should the developer use to verify the functionality
of a new test class before the developer deploys that test class to production? (Select two answers.)

ANSWER FEEDBACK

A. TEST MENU IN THE DEVELOPER CONSOLE Correct. In the Developer Console, you can
execute some or all tests in specific test
classes, set up and run test suites, or run all
tests.

B. RUN TESTS MENU PAGE IN SALESFORCE Incorrect. There is not a page called Run Tests in
SETUP Salesforce Setup.

C. REST API AND APEXTESTRUN METHOD Incorrect. There is not a method called
ApexTestRun.

D. APEX TEST EXECUTION PAGE IN SALESFORCE Correct. You can run unit tests on the Apex
SETUP Test Execution page. The Apex Test Execution
page refreshes the status of a test and
displays the results after the test completes.

7
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 7

A developer has a block of code that omits any statements that indicate whether the code block should
execute with or without sharing.

What will automatically obey the organization-wide defaults and sharing settings for the user who executes the
code in the Salesforce organization?

ANSWER FEEDBACK

Incorrect. Apex generally runs in system context;


meaning the current user's permissions, field-level
A. APEX CONTROLLERS security, and sharing rules aren’t taken into
account during code execution. Apex controllers
do not change this behavior.

Incorrect. Apex generally runs in system context;


meaning the current user's permissions, field-level
B. APEX TRIGGERS security, and sharing rules aren’t taken into
account during code execution. Apex triggers do
not change this behavior.

Correct. Anonymous blocks can execute


existing Apex classes, not merely lines of
C. ANONYMOUS BLOCKS code written in the anonymous block window.
Anonymous blocks execute using the full
permissions of the current user.

Incorrect. Apex generally runs in system context;


meaning the current user's permissions, field-level
D. HTTP CALLOUTS security, and sharing rules aren’t taken into
account during code execution. HTTP callouts do
not change this behavior.

8
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Exam Topic Flashcards


The following flashcards cover testing frameworks, executing tests, and test considerations. Use these
interactive flashcards to brush up on some of the key topics you'll find on this part of the exam.

Read the question or term on each card, then click the card to reveal the correct answer. Click the right-facing
arrow to move to the next card, and the left-facing arrow to return to the previous card.

Question/Term Answer/Definition
A developer creates an Apex
class that has private
methods. What can the Add the @TestVisible attribute to the
developer do to ensure that methods.
the test class can access the
private methods?

A developer needs to ensure


there is sufficient test
coverage for an Apex method
that interacts with Accounts.
The developer needs to Static resources
create test data. What can
the developer use to load
this test data into
Salesforce?

True or false: Loading test


data in place of user input for
True
Flows is valid for execution
by unit tests.

9
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Related Badges

Looking for more information? Explore these related badges.

Badge Content Type

Module

Apex Testing

Module

Developer Console Basics

Module

User Authentication

Congratulations! You’ve studied up on all things related to testing. Up next, let’s dive in to the exam section on
debugging and deployment. Let's go!

10
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Unit 2: Review Debugging and Deployment


Learning Objectives
After completing this unit, you'll be able to:
• Describe the environments, requirements and process for deploying code.
• Describe the Salesforce Developer tools such as Salesforce DX, Salesforce CLI, and
Developer Console, and when to use them.
• Describe how to approach debugging system issues, monitoring flows, processes,
asynchronous and batch jobs.

Key Topics

This unit prepares you for the debugging and deployment topics in the Testing, Debugging, and Deployment
section of the Platform Developer I exam. This section of the exam tests these topics.
• Deployment
• Debugging
• Salesforce DX
• Salesforce CLI
• Developer Console

Exam Practice Questions


Ready to jump in? The sample tool below is not scored—it’s just an easy way to quiz yourself. To use it, read
the scenario and click the answer you think is correct. Some questions may have more than one correct
answer. Click Submit and you get a popup telling you whether the answer you chose is correct or incorrect,
and why; if there’s a longer explanation, click and then click anywhere in the window to close it. When you
reach the end you can review the answers or retake the questions.

11
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 1
A developer created an Apex trigger using the Developer Console and now wants to debug code. How can the
developer accomplish this in the Developer Console?

ANSWER FEEDBACK

A. SELECT THE OVERRIDE LOG Incorrect. There is no Override Log Triggers checkbox.
TRIGGERS CHECKBOX FOR THE
TRIGGER.

B. OPEN THE PROGRESS TAB IN THE Incorrect. There is no Progress tab in the Developer
DEVELOPER CONSOLE. Console.

C. OPEN THE LOGS TAB IN THE Correct. Use the Logs tab in the Developer Console to
DEVELOPER CONSOLE. open debug logs.

D. ADD THE USER NAME IN THE LOG Incorrect. The Log Inspector tracks the logs; there is no
INSPECTOR. way to add a user name to it.

12
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 2
Which two types of information does the Checkpoints tab in the Developer Console provide? (Select two
answers.)

ANSWER FEEDBACK

A. NAMESPACE Correct. The Checkpoints tab displays a list of saved


checkpoints that preserve a snapshot of the state of
objects in memory at the time the checkpoint was
reached. Each checkpoint displays the namespace of
the package containing the checkpoint.

B. EXCEPTION
Incorrect. The Checkpoints tab does not display exception
information.

C. TIME Correct. The Checkpoints tab displays a list of saved


checkpoints that preserve a snapshot of the state of
objects in memory at the time the checkpoint was
reached. Each checkpoint displays the date and time
the checkpoint was reached.

D. DEBUG STATEMENT Incorrect. The Checkpoints tab does not display debug
statement information.

13
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 3
What are two valid source and destination pairs that can send or receive change sets? (Select two answers.)

ANSWER FEEDBACK

Incorrect. Sending a change set between two orgs


A. DEVELOPER EDITION SANDBOX TO requires a deployment connection. Change sets can be
SANDBOX sent only between orgs that are affiliated with a production
org.

Correct. Sandbox to production, production to


sandbox, and sandbox to sandbox are all allowed as
B. SANDBOX TO PRODUCTION long as the developer creates sandboxes from the
same production org and configures the orgs to
accept incoming change sets.

C. DEVELOPER EDITION ORG TO Incorrect. Change sets can only be sent between orgs that
PRODUCTION are affiliated with a production org.

Correct. Sandbox to production, production to


sandbox, and sandbox to sandbox are all allowed as
D. SANDBOX TO SANDBOX long as the developer creates sandboxes from the
same production org and configures the orgs to
accept incoming change sets.

14
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 4
Which two components can you deploy using Metadata API? (Select two answers.)

ANSWER FEEDBACK

Incorrect. You can’t retrieve or deploy the Console Layout


A. CONSOLE LAYOUT with the Metadata API. You must make changes to the
Console Layout manually.

Correct. You can deploy the Account Layout using the


B. ACCOUNT LAYOUT
Metadata API.

Incorrect. You can’t retrieve or deploy the Case Feed with


C. CASE FEED LAYOUT the Metadata API. You must make changes to the Case
Feed Layout manually.

Correct. You can deploy the Case Layout using


D. CASE LAYOUT
Metadata API.

15
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Scenario 5
Which two answers are true for a partial sandbox but do not apply to a full sandbox? (Select two answers.)

ANSWER FEEDBACK

Correct. Partial sandboxes refresh every 5 days, while


A. MORE FREQUENT REFRESHES
full sandboxes refresh every 29 days.

Incorrect. Both partial sandboxes and full sandboxes use


B. USE OF CHANGE SETS
change sets.

Correct. Partial sandboxes have a data storage limit of


C. LIMITED TO 5 GB OF DATA
5 GB, while full sandboxes match the production org.

D. ONLY INCLUDES NECESSARY Incorrect. Partial sandboxes include the metadata as well
METADATA as sample data.

16
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Exam Topic Flashcards


The following flashcards cover debug logs and the different environments used in the development and
deployment process. Use these interactive flashcards to review some of the key topics you’ll find on the exam.

Read the question or term on each card, then click on the card to reveal the correct answer. Click the right-
facing arrow to move to the next card, and the left-facing arrow to return to the previous card.

Question/Term Answer/Definition
In which Salesforce environment
should a developer build a Developer Edition
managed package?

What is the minimum log level


needed to see user-generated DEBUG
debug statements?

17
Platform Developer I Certification Prep: Testing, Debugging and Deployment

Related Badges

Looking for more information? Explore these related badges.

Badge Content Type

Module

Asynchronous Apex

Module

AppExchange App Deployment

Great work! You’ve reviewed the testing, debugging, and deployment sections of the Platform Developer I
exam.

18

You might also like