Salesforce PD2 Exam Results & Testing Guide
Salesforce PD2 Exam Results & Testing Guide
# What’s new?
Display Past Results
$ FAQ’s
) Blog
User Interface (20%) Part 3 – PD2 26-Aug-2020 83.33 %
Categories
Testing 79.49%
VIEW INCORRECT
Questions
1. A developer has created the following unit test method to test the processing of an account by an Apex class named
'AccountProcessor'. Which system method should be used to prove that the new field values of the processed account record are the
same as expected? @isTest public static void testAccountProcessor () { Account acc = new Account (Name = 'Test Account', Rating =
'Hot', Industry = 'Manufacturing'); insert acc; AccountProcessor.accountMethod(acc); } Choose 1 answer.
System.debug()
System.assertEquals()
System.equals()
System.process()
Correct
The System.assertEquals(expected, actual, message) method can be used to prove that the expected and actual arguments are the same. If they are
not the same, an error is returned with the specified message that causes code execution to stop. In this case, assuming that the value of the Rating
field was changed to ‘Cold’ by the AccountProcessor class, the system method can be used as follows to prove that the new value of the field is as
expected.
System.assertEquals(‘Cold’, acc.Rating, ‘The new Rating is different from the expected value’);
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
2. A developer is setting up reusable test data in a separate utility class that can be called by test methods of the organization. Which
of the following are valid considerations for using this practice? Choose 2 answers.
A reusable test utility class that creates test data should have @testSetup annotation
Methods in a test utility class can take parameters and return a value
Methods in a test utility class that are directly called by test classes can be private, public, or global
The @isTest annotation ensures that the code in the test utility class is excluded from the organization's code size limit
Correct
The @isTest annotation can be used for a public test utility class that contains reusable code for test data creation. Like regular Apex class methods,
methods of a test utility class can take parameters and return a value. The methods should be declared as public or global so that they are visible to
test classes that contain the unit tests. Without the @isTest annotation, the code in the test utility class is not excluded from the organization’s code
size limit.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
3. A developer needs to test certain Apex code in different user contexts. The test code needs to be executed as different users with
distinct levels of access in the organization. Which of the following system methods should be used for this use case? Choose 1
answer.
System.executeAs()
System.setTestUser()
System.runAs()
System.setCurrentUser()
Correct
The System.runAs() method should be used to change the current user to a specified user. It can be used to test code in different user contexts. It
enforces record sharing but not user or field-level permissions.
System.executeAs(), System.setTestUser() and System.setCurrentUser() are invalid methods.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
4. A developer who is executing certain test classes from the Developer Console has encountered an UNABLE_TO_LOCK_ROW error.
What can be done to prevent this error? Choose 2 answers.
Correct
An UNABLE_TO_LOCK_ROW error can occur if multiple tests try to update the same record simultaneously. This generally happens when they don’t
create their own test data. In other cases, since tests executed from the Developer Console run in parallel, a deadlock occurs when they try to create
records with duplicate index field values. This can be prevented by disabling Parallel Apex Testing by navigating to ‘Apex Test Execution’ in Setup and
clicking ‘Disable Parallel Apex Testing’.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
5. A developer is trying to create an account record and a user record in the same test method. However, when the test is executed, it
returns a mixed DML error. What can be done to prevent this error and allow the developer to perform both types of DML operations in
the test method? Choose 2 answers.
Create a second method to perform the DML operation for the User sObject
Create a method with @future annotation to perform one of the DML operations asynchronously
Incorrect
A DML operation on a setup sObject and another sObject is not allowed in the same transaction. However, it is possible to perform mixed DML
operations in test methods by enclosing them within a System.runAs block. It is also possible to create a method with @future annotation to perform
one of the DML operations asynchronously, while the other is executed in the original transaction.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
6. A developer wants to use a @testSetup annotation in a test class to create data. What are some considerations he needs to keep in
mind when using this annotation? Choose 3 answers.
Tests must explicitly call the @testSetup method before doing any further execution
If a test deletes data, you must re-run the setup method before doing the next test.
Any changes to test data are rolled back after each test method finishes execution.
The annotation can't be used if any part of the class is annotated with @isTest(SeeAllData=true)
Correct
Only one @testSetup method can be defined in a class, and it runs automatically before any tests are started. Any changes made to setup data by a
test are rolled back to the original setup state before the next test runs. @testSetup can only be used in a class if the (seeAllData=true) option is
excluded from @isTest annotations.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
7. A developer wants to create common data that will be available to various test classes. Which methods are available to make this
work? Choose 2 answers.
Use @isTest(SeeAllData=true)
Correct
A test data factory is a public test class that contains reusable code for test data creation. It can be defined using the @isTest annotation, is excluded
from the organization’s code size limit, and can be called by test methods. The methods of a test data factory are defined the same way as methods of
a non-test class.
Test data can also be loaded using the Test.loadData method. Data can be populated in test methods without writing multiple lines of code. To use
this method, the test data is added to a .csv file. A static resource is created for the .csv file. Test.loadData can be called within a test method, passing
it the sObjectType token and the static resource name
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
8. Which of the following are interfaces that allow developers to create mock responses for testing webservice callouts? Choose 2
answers.
HttpCalloutMock
WebServiceMock
ResponseMock
CalloutServerMock
Correct
HttpCalloutMock allows developers to create a mock response when testing HTTP callouts, while WebServiceMock allows creation of a mock
response based on classes generated by WSDL2Apex. ResponseMock and CalloutServerMock are not valid Apex interfaces.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
9. When testing webservice callouts, what method needs to be called to specify the mock response to be used during the test? Choose
1 answer.
Test.startMock()
Test.Mock()
Test.MockResponse()
Test.setMock()
Correct
Use Test.setMock() before doing a callout test to specify which class should provide the mock response. Failing to call this method will cause your
test run to fail, since tests don’t support live callouts.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
10. Which of the following statements are true about using static resources for loading test data? Choose 2 answers.
The first line must contain the API names of the fields to be loaded
Correct
Static resources used to load test data must be loaded from a .csv file. You can only load records for a single object from each file. To load data into
multiple objects, you will need to create multiple static resources — one for each object to be loaded.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
11. A developer has created a Visualforce page with a custom controller that expects the query parameter '?x=y' in the URL of the page
to display another page once a user clicks a button. Which of the following is the correct method of setting the query parameter in the
test method for the custom controller? Choose 1 answer.
ApexPages.currentPage().getParameters().set('x', 'y');
ApexPages.currentPage().getParameters().get(x, 'y');
ApexPages.currentPage().getParameters().put('x', 'y');
ApexPages.currentPage().getParameters().set(x, 'y');
Incorrect
When testing custom controllers and controller extensions, query parameters can be set and used in test methods using
ApexPages.currentPage().getParameters().put(‘parameterName’, ‘parameterValue’).
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
12. A custom controller has been created with a method named 'execute()' that performs some processing and returns a
PageReference. If a custom controller variable named 'controller' has been declared, how can a developer test whether the button
associated with the method works as expected? Choose 1 answer.
PageReference pr = ApexPages.currentPage().controller.execute();
PageReference pr = controller.execute();
PageReference pr = ApexPages.controller.execute();
PageReference pr = Test.setCurrentPage(controller.execute());
Incorrect
When testing an action method in a custom controller or controller extension, the method is called directly to simulate an action performed by a
user. If the method returns a PageReference, it can be verified with the help of System.assertEquals() and the getUrl() method.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
13. A developer needs to create a unit test class for a custom controller that allows a user to enter data on a Visualforce page and
display it after a button is clicked. Which of the following steps would be necessary? Choose 3 answers.
Correct
A test class for a custom controller is annotated with the @isTest annotation. The custom controller is instantiated in a test method. Thereafter, the
setter and action methods of the custom controller are called in the test method to simulate user input and action, respectively. It is not essential to
call a method of a public test utility class.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
14. A custom controller redirects a user to another Visualforce page based on input. Which of the following methods can be used in a
unit test to verify that the resulting PageReference variable is the same as expected? Choose 1 answer.
getParameters()
getContent()
getResource()
getUrl()
Correct
The getParameters() method would return the URL parameters but not the complete URL associated with the PageReference. The getContent() call
is not supported in a unit test. There is no PageReference method called getResource(). The getUrl() method can be used in a System.assertEquals()
statement to verify that the PageReference variable is the same as expected.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
15. A developer needs to test the functionality of a controller extension. The code below shows the instantiation of the standard
controller in a test method, where 'acc' is a variable of the Account sObject. ApexPages.StandardController sc = new
ApexPages.StandardController(acc); If 'ControllerExtension' is the name of the controller extension class, which of the following code
statements represents the correct method of its instantiation? Choose 1 answer.
Incorrect
A controller extension is instantiated by passing the variable of the controller as a parameter to the extension constructor. In this case, the variable
‘sc’ is passed as the parameter.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
16. An Apex class contains a private method that needs to be called by a unit test method of a test class for the purpose of testing
some functionality. Which of the following annotations can be used to make the private method visible to the unit test class? Choose 1
answer.
@isTest
@testMethod
@testVisible
@testSetup
Correct
The @testVisible annotation can be used in the definition of any private or protected variable, method or inner class to make it visible to a unit test
class. With this annotation, it is possible to access methods and member variables without changing their access modifiers.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
17. A developer has created a unit test class and annotated it with @isTest (SeeAllData=true) annotation at the class level. A test
method within the class has been annotated with @isTest(SeeAllData=false) annotation. Which outcome will be observed by the
developer who is trying to prevent data access at the method level? Choose 1 answer.
The @isTest (SeeAllData=false) annotation at the method level will override the annotation at the class level
Executing the test with both the annotations will result in an error
Correct
If a test class has been annotated with @isTest (SeeAllData=true) annotation, annotating any test method of the class with @isTest
(SeeAllData=false) is ignored for that method. However, annotating a method with @isTest (SeeAllData=true) overrides the @isTest
(SeeAllData=false) annotation on the class.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
18. A developer would like to reduce the code coverage calculation time when executing many tests on large volumes of code. Where
is it possible to select the option to store only aggregated code coverage for this use case? Choose 1 answer.
Developer Console
Developer Workbench
Incorrect
The Apex Test Execution page in Setup has certain options available for selection, including the option to ‘Store Only Aggregated Code Coverage’. It
is not possible to select this option in the Developer Console, Visual Studio Code or the Developer Workbench.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
19. A developer working in the Developer Console needs to execute a unit test class that is likely to take a considerable amount of time.
He also needs to perform other tasks in the Console, such as analyzing the execution log of a recent Apex transaction. What can the
developer do to work in other areas of the Developer Console while the test is running? Choose 2 answers.
Run the test class from the 'Apex Test Execution' page in Setup
Run the test class from the 'Apex Classes' page in Setup
Correct
A unit test class can be executed from the Salesforce user interface by navigating to the ‘Apex Test Execution’ page in Setup. Tests that are executed
from this page run asynchronously, which means that the developer does not have to wait for a test class execution to finish. The page refreshes the
status of a test and displays the results after the test completes. It is also possible to run a single test class asynchronously from the Developer
Console by choosing the ‘Always Run Asynchronously’ option in the Test menu. The ‘Apex Classes’ page in Setup only allows the execution of all tests.
The runTests() call from the SOAP API is used to run tests synchronously.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
20. A developer needs to execute certain tests asynchronously at specific times using the Apex scheduler. Which of the following
objects can be used for this requirement? Choose 2 answers.
ApexTestSuite
ApexTestQueueItem
ApexTestQueue
ApexTestResult
Incorrect
Apex tests can be run asynchronously using ApexTestQueueItem and ApexTestResult. Tests can be added to the Apex job queue using
ApexTestQueueItem. The results of the completed test runs can be checked using ApexTestResult.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
21. A developer would like to speed up test runs for a few Apex test classes by skipping the collection of code coverage information.
Where can the option to skip code coverage be selected in a Salesforce org? Choose 2 answers.
Correct
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 ‘Settings’ button can be clicked to specify whether code coverage should be skipped. 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.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
22. Which of the following statements are true about skipping code coverage for an Apex test run from the Developer Console? Choose
3 answers.
Incorrect
Skipping code coverage increases the speed of a test run and allows receiving faster feedback on the pass or fail status of the test run. No data about
coverage information is stored. The Suite Manager cannot be used to skip code coverage, but it is possible to do so while creating a new test run for a
suite. It is also possible to select this option while creating a new test run for a single test class.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
23. A developer executed a test using the Developer Console and received an UNABLE_TO_LOCK_ROW error. What can he do to
prevent the occurrence of this error? Choose 1 answer.
Correct
The Salesforce UI and Developer Console execute tests in parallel to speed up run time. Due to this behavior, tests may update the same records at
the same time, or records are created with duplicate index field values. These issues are reported as UNABLE_TO_LOCK_ROW errors in the log. To
prevent this from happening, parallel test execution can be disabled in Setup.
Increasing code coverage cannot prevent this error. Defining a test class with the IsTest(SeeAllData=true) annotation gives it access to all the data in
the organization, which can actually cause data contention issues and UNABLE_TO_LOCK_ROW errors. There is no auto-lock row feature.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
24. A developer has written a test class for an Apex trigger that links packages (Package__c) to an account if the value of a custom
field called 'Is_Package__c' on the Account object is set to true. The package records are created and maintained by the sales
department head. The Apex trigger has been deployed to the production org. However, sales users have noticed that no packages are
being linked to newly created accounts. The developer has discovered that they do not have access to the package records owned by
the department head. Given the test class below, what method could have been used to catch this issue earlier? Choose 1 answer.
@isTest
public class PackageTest {
@isTest
static void testPackage() {
Correct
System.runAs() is used to run a test in the context of a specified user. It enforces record sharing only. A test sales user can be created in the test
method and then the test can be run as this user.
System.UserContext() is not a valid method.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
25. A test class is not meeting the required code coverage. Given the Apex class and its test class below, what can be done to improve
the code coverage results? Choose 1 answer.
//Apex class
if (age < 1) {
amount = price - (price * 0.10);
} else if (age >= 1 && age < 2) {
amount = price - (price * 0.12);
} else if (age >= 2 && age < 3) {
amount = price - (price * 0.14);
} else if (age >= 3 && age < 4) {
amount = price - (price * 0.16);
} else if (age >= 4 && age < 5) {
amount = price - (price * 0.18);
} else {
amount = price - (price * 0.2);
}
} else {
return amount;
}
}
@isTest
private class ParkTest {
@isTest
static void testAge() {
@isTest
static void testAmount() {
Correct
The test methods only execute two scenarios of the if statement in the Apex class – one where the amount is greater than 51 and age is 2, and the
other where the amount is 50 and age is 5. Code coverage can be improved considerably by adding more methods to the class or updating test
method logic to cover all possible scenarios.
The SeeAllData=true annotation would not help as it only enables the test method to access the org data. Test.startTest and Test.stopTest are not
useful here as exceeding governor limits is not the issue. The method also does not perform asynchronous calls. The assertions are properly used, so
there is no need to modify the associated system methods.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
26. A test class was created for an Apex trigger that generates a Promo record with a Type__c field populated based on the Type of the
Account it is associated with. After the feature was rolled out in the production org, they noticed that the Promo Type does not match
with the Account Type for some reason. What could be added to the test class below for this to discover this issue during deployment?
Choose 1 answer.
@isTest
public class PromoTriggerTest {
@isTest
static void testTrigger() {
Add an Assert method to verify that the Promo type matches the Account type
Use System.RunAs() to automatically compare the Promo type and Account type
Use @testSetup on the method to check if the two objects are properly set up
Correct
An additional assertion statement should be added to check that the Promo type matches the Account type.
System.RunAs() is used for executing test in the context of another user. @testSetup is used for generating test data. Test.startTest() is used to
receive a fresh set of governor limits.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
27. A Salesforce developer was asked to build functionality that would generate a set of gift records if the stage of a customer
opportunity changes from 'Contract Signing' to 'Closed Won' . The Apex tests successfully passed in the sandbox. During deployment
to production, the tests are getting 0% code coverage. Given the test class below, what could be a likely cause? Choose 1 answer.
@isTest(SeeAllData=true)
public class OpportunityTriggerTest {
@isTest
static void testGifts() {
The target org did not have data needed by the test class
Correct
As a best practice, a test class should generate its own test data so that it does not depend on org data for it to perform its test. In the scenario above,
if there were no Opportunity records in the target org that have the stage ‘Contract Signing’, an error would have been thrown, causing the test to
terminate and return a 0% code coverage.
@isTest(AccessData=true) is not valid. Tests run in system mode by default, so using System.runAs() is not required. Adding isParallel=true will only
cause the test to be run in parallel.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
28. A developer is writing a test class for an Apex trigger mechanism between an Opportunity and its related Account by updating an
existing utility class to generate its test data. There was an issue with optimizing the code coverage because the utility class contained
methods that weren't executed by the test class. What options should the developer consider given the utility class below? Choose 2
answers.
Correct
Annotating the test class with @isTest converts the utility class into a test utility class and excludes it from the code coverage percentage calculation.
However, creating a separate test utility class for the trigger test class should also be considered because once @isTest is added to the existing utility
class, it cannot be called by non-test code and will be exclusively used by testing methods only.
There is no @isTestUtility annotation. Test data is a prerequisite for the trigger. Also, triggers cannot contain methods.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
29. A developer has added a feature in an org for a real estate company that generates a number of Property__c records based on a
numeric Property_Count__c field on the related Contact. After a while, it was noticed that some contacts have negative
Property_Count__c field values and, worse, properties were still created for these contacts. What should be added to the test class
below to catch this issue? Choose 1 answer.
@isTest
public class ContactPropertyTest {
@isTest
static void testTriggerPos() {
Correct
The test class above is an example of a positive unit test that demonstrates how code should behave when given a valid input. As such, a negative unit
test should also be created to ensure that code behaves as expected when given an invalid input.
Test setup methods are used for creating test data for test methods to use. System.runAs methods are used when a test needs to run in the context
of a specified user. startTest and stopTest methods are used to refresh governor limits.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
30. A trigger was deployed by a developer for a non-profit organization that generates certain metrics for volunteers based on their
skillset. It was running successfully until they noticed that the feature crashes when there are thousands of volunteers. Upon checking,
the developer found out that the trigger was hitting the governor limits. Given the test class below, what can be done to catch the
issue? Choose 2 answers.
@isTest
public class VolunteerTriggerTest {
@isTest
static void testMetrics() {
Integer numOfMetrics = 3;
Event__c event = MyTestDataFactory.createEvent();
Correct
It is important to test code for bulk operations to catch issues caused by processing multiple records in a single transaction. The startTest and
stopTest methods should be used in this case to encapsulate the actual test to receive a fresh set of governor limits and help identify the source of a
limit exception.
Parallel test execution enables tests to be run in parallel. The @Testvisible annotation enables a private or protected member of a non-test class to be
accessible by test methods.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
31. A DML limit exception is encountered in a for-loop for a particular Apex test. The developer wants to find out at which iteration the
exception is triggered. What can be done to the test class below to achieve this? Choose 2 answers.
@isTest
public class OpportunityTest {
@isTest
static void testOpportunityTrigger() {
// create opportunity
insert opp;
}
}
}
Incorrect
The Test.startTest() and Test.stopTest() methods are used to allow code between the two statements to be executed under a fresh set of governor
limits. Limit methods such as Limits.getDmlStatements() and Limits.getLimitDmlStatements() can be used to perform a check and avoid hitting the
governor limit for DML statements.
A try-catch block will not be useful since limit exceptions cannot be handled in Salesforce. Switching to a while loop will have no relevant effect.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Given a scenario or Apex tests that are not performing as expected, apply techniques and tools to isolate and identify the issues.
32. What is true about common utility test classes? Choose 2 answers.
These classes are excluded from the organization code size limit.
Their methods can be called by any test method used to set up test data.
Correct
Test utility classes are defined with the @isTest annotation, so they are not included in the organization code size limit. The methods can be called by
any test method used for setting up test data.
Test utility class methods can take parameters and return values just like non-test methods do, but they can only be called by test methods.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
33. Which system assert methods can a developer use in a test class to validate output of business logic? Choose 2 answers.
System.assertEquals()
System.assertNotEquals()
System.equalsAssert()
System.equalsNotAssert()
Correct
The System.assertEquals method asserts that the output equals the specified value, while the System.assertNotEquals method asserts that the
output does not equal the specified value.
System.equalsAssert and System.equalsNotAssert are invalid methods.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
34. There is a requirement that only users from the customer support team should be able to access case records, and other users
should be prohibited from accessing them. Which method can a developer use in a test class to test this? Choose 1 answer.
RunAs method
Limit method
Assert method
Access method
Correct
The RunAs method can be used to execute actions in the context of a specified user and test record visibility, for instance, in the org based on that
running user.
Limit methods are used to determine governor limit status. Assert methods are used to validate results of business logic. There is no Access method.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
35. A developer has built a feature that extracts social media data of a contact during creation through a third-party platform via an
HttpRequest instance. What does the developer need to do to test the HTTP callout? Choose 2 answers.
Correct
By default, HTTP callouts are not supported by test methods. The HttpCalloutMock interface can be used to simulate the response of a forwarded
HTTPRequest. The implemented class will include a respond method that returns predefined data for the calling method. The Test.setMock method
is used in the test class to set the implementing class.
The @testSetup annotation is used on methods that generate records used for testing. Using System.runAs method to run as a certain user will not
have any effect on HTTP callout limitations.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Apex classes and triggers.
36. A developer has built a custom controller that is used in multiple Visualforce pages. To determine which of the Visualforce pages is
being tested in a unit test, what Apex method is used? Choose 1 answer.
Test.setCurrentPage
System.setCurrentPage
Test.setVisualforcePage
System.setVisualforcePage
Correct
The Test.setCurrentPage method is used to set the PageReference and configure the unit test to invoke controller behavior in the context of the
Visualforce page that is specified.
The other options are all invalid methods.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
37. To ensure that the save method of a Visualforce page produces the expected result, an assert method should be used in its unit
test. Given its custom controller and test class below, which assert statements are valid? Choose 2 answers.
// custom controller
public class InventoryController {
PageReference pr = null;
if (this.isValidSerialNumber()) {
pr = new PageReference('/apex/product');
pr.getParameters().put('sn', this.getSerialNumber());
} else {
pr = new PageReference('/apex/inventory');
pr.getParameters().put('error', 'invalidSerialNumber'); // append error code
}
pr.setRedirect(true);
return pr;
}
...
}
@isTest
public class InventoryControllerTest {
@isTest
public static void testViewItemDetails() {
System.assertEquals('/apex/inventory?error=invalidSerialNumber', errorUrl);
System.assertEquals('/apex/product?sn=AA-123', successUrl);
System.assertEquals('/apex/inventory?sn=AA-123', errorUrl);
System.assertEquals('/apex/product?error=invalidSerialNumber', successUrl);
Correct
The assertEquals method asserts that the value of its first argument equals the second one.
Based on the controller logic, if the serial number is valid, a PageReference is returned with the URL ‘/apex/product’ and the serial number appended
as a parameter. Otherwise, the PageReference returned will have the URL ‘/apex/inventory’ and the error code appended to the URL.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
38. A developer has built a Visualforce page to contain a feedback form for the customer service department. How can the developer
simulate user input on the form's text fields to test input data in the unit test? Choose 1 answer.
Invoke JavaScript code from Apex to populate the text input field
Manually populate the form and call the form from the unit test
Correct
To simulate user input on a Visualforce page, the variable associated with input field is set by calling the setter method.
JavaScript cannot be used in a unit test. There is no Test.setCurrentField method. It is not possible to manually populate a form and incorporate it in
a unit test.
Salesforce Reference Link
Salesforce Reference Link 2
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
39. A developer has created a button on a Visualforce page using the component that performs a certain action on the current record.
How can the developer test the button in a unit test? Choose 1 answer.
Call the action method directly that is associated with the button
Specify the test method to execute in the onclick attribute of the button
Correct
The controller method associated with the apex:commandButton component is specified in its action attribute. When testing buttons in Visualforce
pages, their action methods are called directly in the unit test.
Unit tests are written in Apex. Thus, JavaScript cannot be used. A test method cannot be used on the onclick attribute as it requires a JavaScript
function. There is no Test.setCurrentButton method.
Salesforce Reference Link
Objective: Testing
Detailed Objective: Apply techniques and tools for testing Visualforce controllers and controller extensions.
« Previous 1 2 3 4 … 20 Next »
Display your score and detailed results for the past 3 months. All past scores are available. Due to performance and storage constraints, detailed
results older than 3 months are removed.
Copyright 2020 - www.focusonforce.com About Blog Contact Us Disclaimer Privacy Policy Terms of Use View as Mobile
Privacy - Terms