Testing, Debugging and Deployment Flashcards

1
Q

Unit tests for Apex classes are not created just so that Apex code can simply be deployed to production but, most importantly, to validate that the Apex classes work as expected. Which option represents a recommended approach to performing Apex unit tests?

A. Annotate @SeeAllData=true on the test class. Execute the methods to be tested and verify the results using assertions.
B. Annotate @SeeAllData=true on the test class. Execute the methods to be tested and verify the results using System.debug();
C. Create valid test data for testing. Execute the methods to be tested and verify the expected results using assertions.
D. Query test data on the organization. Execute the methods to be tested and verify the expected results using assertions.

A

✅ C. Create valid test data for testing. Execute the methods to be tested and verify the expected results using assertions.
🧠 Explanation:
The recommended practice for Apex unit testing is to create your own test data within the test class. This ensures the test is independent, predictable, and not dependent on external or production data. Assertions should be used to verify expected results. This improves test reliability and ensures tests remain valid across orgs and over time.

❌ Why the other options are incorrect:
- A and B: Using @SeeAllData=true is discouraged because it makes the test depend on existing data in the org, which may change. Also, System.debug() does not verify anything — it’s for inspection only, not testing.
- D: Querying org data (without creating it in the test) leads to unreliable tests. Salesforce recommends not relying on org data for unit tests.

🔗 Documentation:
- Apex Testing Best Practices
- Test Class Data Isolation (@isTest and SeeAllData)

📚 Additional Resources:
- Trailhead: Apex Testing
- Apex Unit Testing Video Guide (YouTube)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which are true regarding the runAs() method?

Choose 2 answers.

A. runAs() ignores user license limits
B. runAs() only enforces record sharing
C. runAs() can be used with existing users or a new user
D. runAs() can be used in any Apex method

A

✅ A. runAs() ignores user license limits
✅ C. runAs() can be used with existing users or a new user
🧠 Explanation:
- A. Correct: The runAs() method is designed for test context only and does not enforce user license limits. You can create test users in your code and run code as that user even if the org doesn’t have available licenses.
- C. Correct: You can use runAs() with either a user that already exists or one you create programmatically with insert in your test context.

❌ Why the others are incorrect:
- B. Incorrect: runAs() enforces both record sharing and object-level permissions in test methods, not only record sharing.
- D. Incorrect: runAs() can only be used in test methods. It cannot be used in regular Apex code that runs outside test context.

🔗 Documentation:
- Testing Apex with runAs()
- User Context in Tests

📚 Additional Resources:
- Trailhead: Apex Testing
- runAs() method explained (blog)
Using the runAs Method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A Salesforce developer needs to deploy a package from a UAT environment to a production org that has the following components:

7 Custom Objects
43 Custom Fields
15 Validation Rules
20 Apex Classes
5 Apex Triggers

The production org runs on API version 33.0. What will happen during deployment when the default test is executed for the package?

A. No tests are run during the deployment.
B. All local tests are run during the deployment.
C. Running test classes are not required.
D. All local and managed package tests are run during the deployment.

A

✅ B. All local tests are run during the deployment.
🧠 Explanation:
Since the production org runs on API version 33.0, and the default test level is used during deployment, only local tests are executed — this means tests that are part of the code being deployed and any existing code in the target org not part of a managed package.

This behavior is governed by Test Levels in Metadata Deployments.

❌ Why the other options are incorrect:
- A: Incorrect. Tests are required for deployment of Apex code and triggers to production.
- C: Incorrect. Test classes are required for deployment unless using specific test levels (like RunSpecifiedTests or RunNoTests) which is not the case here.
- D: Incorrect. Managed package tests are not run unless using RunAllTestsInOrg, which is not the default.

🔗 Documentation:
- Deploying Metadata with Test Levels
- Testing and Code Coverage Requirements

📚 Additional Resources:
- Trailhead: Develop with Apex
Using the runAs Method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following activities are involved when performing unit testing in Apex?

Choose 1 answer.

A. Deleting test data after testing has been completed
B. Inspecting code coverage after running unit tests
C. Having enough licenses for users created via runAs()
D. Ensuring that testers have Visual Studio Code installed

A

✅ B. Inspecting code coverage after running unit tests
🧠 Explanation:
Inspecting code coverage is a key step in Apex unit testing. Salesforce requires 75% code coverage in production deployments that include Apex. After running tests, developers review code coverage to ensure this requirement is met and to identify untested areas.

❌ Why the other options are incorrect:
- A: Test data is not persisted after test execution. It’s automatically rolled back, so there’s no need to manually delete it.
- C: runAs() ignores license limits during testing, so you don’t need real licenses for test users.
- D: Visual Studio Code is a recommended tool for development, but it’s not required to perform unit testing in Apex.

🔗 Documentation:
- Code Coverage in Apex Testing
- Best Practices for Apex Testing

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Monitor and Improve Code Coverage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is true regarding the Apex testing framework?

Choose 3 answers.

A. Apex test classes can access org data such as leads by default.
B. Unit tests can test single and bulk actions.
C. Unit tests cannot perform callouts to external web services.
D. Unit tests cannot send outbound email.
E. Records inserted by unit tests must be deleted.

A

✅ B. Unit tests can test single and bulk actions.
✅ C. Unit tests cannot perform callouts to external web services.
✅ D. Unit tests cannot send outbound email.
🧠 Explanation:
- B. Correct: Apex test methods should test both single-record and bulk operations, especially when testing triggers or batch classes.
- C. Correct: By default, callouts are not allowed in test methods. You must use Test.startTest() with HttpCalloutMock or similar to simulate them.
- D. Correct: Outbound email cannot actually be sent in tests. You can use the Messaging.sendEmail() method, but the email will not go out — this avoids unintended real communications.

❌ Why the other options are incorrect:
- A: By default, test methods do not have access to org data unless annotated with @isTest(SeeAllData=true), which is discouraged.
- E: Test data is automatically rolled back after test execution. You do not need to manually delete it.

🔗 Documentation:
- Apex Testing Framework Overview
- Testing Callouts
- Testing Bulk Triggers

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Apex Test Classes Best Practices

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the procedure for unit testing?

Choose 1 answer.

A. Create test data, run all tests, verify results, delete any records created
B. Create test data, call the method being tested, verify results
C. Create test data, run all tests, delete any records created, and verify the results
D. Create test data, call the method being tested, verify results, delete any records created

A

✅ B. Create test data, call the method being tested, verify results
🧠 Explanation:
The typical unit testing process in Apex is to:
1. Create test data
2. Call the method being tested
3. Use assertions to verify results

You don’t need to delete test data because Apex automatically rolls back any data created in tests, keeping your org clean.

❌ Why the other options are incorrect:
- A, C, D: All mention deleting records, which is unnecessary in Apex testing. Tests run in a separate context and data is not committed to the database.

🔗 Documentation:
- Apex Testing Overview
- Best Practices for Test Methods

📚 Additional Resources:
- Trailhead: Apex Testing
- Apex Testing Patterns Video (YouTube)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following statements about running Apex test classes in the Developer Console are true?

Choose 3 answers.

A. An Overall Code Coverage pane is available that displays the percentage of code coverage for each class in org.
B. If the test run includes more than one test class, the Developer Console always runs tests asynchronously in the background.
C. The [Rerun Failed Tests] option reruns only the failed tests from the test run that are highlighted in the Tests tab.
D. The [Suite Manager] option is used to abort the test selected in the Tests tab.
E. The [New Suite] option is used to create multiple test classes at the same time.

A

✅ A. An Overall Code Coverage pane is available that displays the percentage of code coverage for each class in org.
✅ B. If the test run includes more than one test class, the Developer Console always runs tests asynchronously in the background.
✅ C. The [Rerun Failed Tests] option reruns only the failed tests from the test run that are highlighted in the Tests tab.
🧠 Explanation:
- A. Correct: The Developer Console provides an Overall Code Coverage panel to review coverage across all classes.
- B. Correct: When running multiple test classes, the Developer Console executes the tests asynchronously in the background, allowing you to continue working.
- C. Correct: The [Rerun Failed Tests] button reruns only the tests that failed in the last execution and are highlighted.

❌ Why the other options are incorrect:
- D: The Suite Manager is used to manage test suites, not to abort tests.
- E: The New Suite option creates a test suite (group of existing test classes), not new test classes.

🔗 Documentation:
- Developer Console Overview
- Run Tests in Developer Console

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Developer Console Code Coverage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A developer has written the ‘AccountProcessor’ Apex class below to update the ‘Rating’ field of an account record if the value of its ‘Credit_Status__c’ field is ‘Excellent’. If ‘acc’ is the name of an account variable used for testing in a test method created for this class, which of the following statements can be used to test for a negative scenario?

Choose 1 answer.

public class AccountProcessor {
publ``ic static void accountMethod(Account acc) {
if (acc.Credit_Status__c == ‘Excellent’) {
acc.Rating = ‘Hot’;
update acc;
}
}
}

A. System.assertEquals(‘Hot’, acc.Rating);
B. System.assert(acc.Rating == ‘Cold’);
C. System.assertNotEquals(‘Cold’, acc.Rating);
D. System.assert(acc.Rating != ‘Hot’);

A

✅ D. System.assert(acc.Rating != ‘Hot’);
🧠 Explanation:
To test a negative scenario, we want to verify that the condition does not trigger. In this case, if Credit_Status__c is not ‘Excellent’, the method should not update the Rating field to ‘Hot’.

  • ✅ D is correct because it ensures that the method did NOT apply the logic (i.e., acc.Rating is not ‘Hot’).

❌ Why the other options are incorrect:
- A asserts a positive case, not a negative one.
- B assumes a default ‘Cold’ value, which the method does not assign.
- C asserts a value not being ‘Cold’, which doesn’t prove negative behavior.

🔗 Documentation:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_isTest.htm
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_system.htm

📚 Additional Resources:
- Trailhead: Apex Testing – https://trailhead.salesforce.com/content/learn/modules/apex_testing
- Negative Testing in Apex – https://salesforce.stackexchange.com/questions/133573/how-to-write-negative-test-case-in-apex

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A developer of Cosmic Solutions would like to run all unit tests in Salesforce. Which of the following options are available?

Choose 2 answers.

A. Selecting the ‘Run All’ menu option in Data Loader.
B. Selecting the ‘Run All’ menu option in the Developer Console.
C. Using the ‘Run All Tests’ button on the ‘Test Classes’ page in Salesforce Setup.
D. Using the ‘Run All Tests’ button on the ‘Apex Classes’ page in Salesforce Setup.

A

✅ B. Selecting the ‘Run All’ menu option in the Developer Console.
✅ D. Using the ‘Run All Tests’ button on the ‘Apex Classes’ page in Salesforce Setup.
🧠 Explanation:
- B. Correct: The Developer Console provides a ‘Run All’ option under the Test menu, allowing developers to run all unit tests.
- D. Correct: The Apex Classes page in Setup includes a ‘Run All Tests’ button, enabling the execution of all test methods in the org.

❌ Why the other options are incorrect:
- A: Data Loader is a data import/export tool and does not support running tests.
- C: There is no ‘Run All Tests’ button on the ‘Test Classes’ page; the proper interface is through Apex Classes or the Apex Test Execution page.

🔗 Documentation:
- Run Tests in Developer Console
- Running Apex Tests from Setup

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce: Monitor Test Execution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is true regarding unit tests?

Choose 1 answer.

A. Once test coverage of 75% is reached, no more unit tests should be created
B. 100% of code in triggers must be covered by unit tests
C. All code must execute without throwing any uncaught exceptions
D. Governor limits are not applied to test methods

A

✅ C. All code must execute without throwing any uncaught exceptions
🧠 Explanation:
- C. Correct: A fundamental requirement for unit tests is that no uncaught exceptions should occur during execution. This ensures that the logic behaves as expected under test conditions and is stable enough for production deployment.

❌ Why the other options are incorrect:
- A: Incorrect. Reaching 75% coverage is the minimum required for deployment, but more tests should be created to ensure robustness and cover edge cases.
- B: Incorrect. Triggers must be included in the overall 75% coverage, but there’s no rule requiring 100% coverage.
- D: Incorrect. Governor limits are applied during test execution to ensure your code respects platform constraints.

🔗 Documentation:
- Apex Code Coverage
- Best Practices for Apex Testing

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Understanding Apex Test Results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

A developer has found that test data creation is duplicated across test classes. How can this be eliminated?

Choose 1 answer.

A. De-annotating @isTest on methods
B. Using one common test class
C. Creating a common test utility class
D. Defining test methods as public

A

✅ C. Creating a common test utility class
🧠 Explanation:
- C. Correct: The best practice to avoid duplicated test data is to use a test utility class with reusable methods that generate standard test records. These utility methods can be public static and called from multiple test classes.

❌ Why the other options are incorrect:
- A: Removing @isTest will make the method no longer recognized as a test — this is not a solution.
- B: While a common test class might help, it’s not scalable or flexible. Utility classes are a cleaner solution.
- D: Test methods should be annotated with @isTest and defined as private, not public. Public access is unnecessary and not recommended for test methods.

🔗 Documentation:
- Creating Test Utility Classes
- Apex Test Classes

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Reusable Test Utilities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A developer is selecting and running the same set of test classes repeatedly. What feature can help with making this task more efficient?

Choose 1 answer.

A. Defining a test suite
B. Defining a test set
C. Defining a master test class
D. Reducing the number of test classes

A

✅ A. Defining a test suite
🧠 Explanation:
- A. Correct: A test suite in the Developer Console allows a developer to group a set of test classes and run them together. This is ideal for recurring test runs and saves time by avoiding manual selection.

❌ Why the other options are incorrect:
- B: “Test set” is not a recognized feature in the Salesforce Developer Console or setup tools.
- C: A “master test class” is not an official concept. While you could centralize logic, it wouldn’t help with selecting classes.
- D: Reducing the number of test classes is not a solution — it could compromise test coverage and quality.

🔗 Documentation:
- Run Tests in Developer Console
- Create and Manage Test Suites

📚 Additional Resources:
- Trailhead: Apex Testing
- Video: Salesforce Test Automation Tips

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What steps are required to create test data from files using static resources?

Choose 2 answers.

A. Call Test.loadData() within the test method.
B. Create the test data in a .csv file and upload it as a static resource.
C. Create a static resource and edit to add test data.
D. Call System.loadData within the test method.

A

✅ A. Call Test.loadData() within the test method.
✅ B. Create the test data in a .csv file and upload it as a static resource.
🧠 Explanation:
- A. Correct: Test.loadData() is a method used in test methods to load data from a .csv file uploaded as a static resource.
- B. Correct: The .csv file containing the test data must be created and uploaded as a static resource so that it can be used with Test.loadData().

❌ Why the other options are incorrect:
- C: Static resources cannot be “edited” directly to add data; you upload them with the content already defined.
- D: System.loadData does not exist — the correct method is Test.loadData.

🔗 Documentation:
- Test.loadData() Documentation
- Working with Static Resources

📚 Additional Resources:
- Trailhead: Apex Testing
- Video: Load Test Data with Static Resources

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A developer needs to determine the exact amount of resources that have been consumed in a particular code block with regards to governor limits. Which of the following Test methods can be used in conjunction with Limits methods?

Choose 1 answer.

A. Test.isTest() and Test.isNotTest()
B. Test.getCurrentLimits() and Test.getLimits()
C. Test.beginTest() and Test.endTest()
D. Test.startTest() and Test.stopTest()

A

✅ D. Test.startTest() and Test.stopTest()
🧠 Explanation:
- D. Correct: Test.startTest() and Test.stopTest() are used to reset governor limits in test methods. When placed around a block of code, they allow you to measure resource consumption accurately by starting fresh limits.

❌ Why the other options are incorrect:
- A: These methods do not exist.
- B: Also not real Apex test methods — Limits is the class used to check limits, not Test.getCurrentLimits().
- C: Test.beginTest() and Test.endTest() are incorrect names. The correct methods are startTest() and stopTest().

🔗 Documentation:
- Test.startTest() and Test.stopTest()
- Using Limits Class

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Monitor Governor Limits

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Test methods don’t have access by default to pre-existing data in the organization except for which of the following?

Choose 3 answers.

A. Record Types
B. Custom Settings
C. Users
D. Custom Objects
E. Profiles

A

✅ A. Record Types
✅ C. Users
✅ E. Profiles
🧠 Explanation:
Apex test methods do not have access to real org data by default unless you annotate with @isTest(SeeAllData=true). However, there are exceptions where some metadata and setup data are accessible by default, even without SeeAllData.

  • A. Record Types: These are metadata and are available to test methods without SeeAllData.
  • C. Users: Although users are data records, Salesforce allows access to current user and admin-defined test users. Additionally, test methods can create and query users without SeeAllData.
  • E. Profiles: These are setup data and are always available for querying in test methods.

❌ Why the others are incorrect:
- B. Custom Settings: While accessible in some cases, hierarchy custom settings may not return results in tests unless created within the test context.
- D. Custom Objects: These require you to insert test data. Records from the org are not accessible by default.

🔗 Documentation:
- Testing Data Visibility
- @isTest(SeeAllData) Annotation

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Test Class Data Access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which of the following statements are true regarding running tests from the Salesforce UI?

Choose 2 answers.

A. After test classes are selected, they are placed in the Apex Job queue and will always run in parallel
B. All test classes can be selected
C. Individual test classes can be selected
D. After tests are run, code coverage is available on Apex Test Execution page

A

✅ B. All test classes can be selected
✅ D. After tests are run, code coverage is available on Apex Test Execution page
🧠 Explanation:
- ✅ B. Correct: From the Salesforce UI, specifically in the Apex Test Execution section, developers can select all test classes to run in a batch.
- ✅ D. Correct: After the tests are executed, you can view code coverage details directly in the Apex Test Execution and Code Coverage pages.

❌ Why the other options are incorrect:
- A: While test classes are placed in the Apex Job queue, they do not always run in parallel — Salesforce may run them serially depending on system load or configuration.
- C: You cannot always run individual test methods via UI. You can select individual classes, but the option here is ambiguous when contrasted with B.

🔗 Documentation:
- Run Tests from Setup UI
- Code Coverage Viewer

📚 Additional Resources:
- Trailhead: Apex Testing
- Monitor Apex Tests

17
Q

Which of the following statements are true about creating unit tests in Apex?

Choose 2 answers.

A. Use the System.assert() method to test your application in different user contexts.
B. Lines of code in Test methods and test classes are not counted as part of calculating Apex code coverage.
C. If code uses conditional logic (including ternary operators), one scenario will automatically cover all conditions.
D. Since data created in tests do not commit, you will not need to delete any data.

A

✅ B. Lines of code in Test methods and test classes are not counted as part of calculating Apex code coverage.
✅ D. Since data created in tests do not commit, you will not need to delete any data.
🧠 Explanation:
- ✅ B. Correct: Test classes and test methods do not count toward the Apex code coverage percentage. Only lines of code in non-test classes and triggers are measured.
- ✅ D. Correct: Data created within test methods is rolled back automatically after the test runs — no need to delete it manually.

❌ Why the others are incorrect:
- A: System.assert() is used to verify expected outcomes, not for testing user context. Use System.runAs() for that.
- C: Conditional logic needs multiple scenarios to be tested — ternary operators or if-else blocks must be covered with different input values to reach all branches.

🔗 Documentation:
- Apex Code Coverage
- Test Data Lifespan

📚 Additional Resources:
- Trailhead: Apex Testing
- Video: Writing Effective Apex Unit Tests

18
Q

Unit tests need to be created for testing new functionality added to an Apex class that is used as a controller of an account management tool. If the variable ‘a’ represents an Account record in the code snippet of a unit test below, which of the following options represents code that should be used to replace the placeholder comments?

Choose 2 answers.

a.addError(‘Site’, ‘Site is not accessible!’);
//Add code to assert that an error was added to the account instance
//Add code to retrieve any errors added to the account instance
System.assertEquals(errors.size(), 1);

A

✅ A. System.assertEquals(a.hasErrors(), true);
✅ B. List<Database.Error> errors = a.getErrors();
🧠 Explanation:
- ✅ **A. Correct**: `a.hasErrors()` is a method that checks if an SObject instance has any errors attached to it. It returns a boolean.
- ✅ **B. Correct**: `a.getErrors()` retrieves the list of `Database.Error` objects added to the record with `.addError()`. This is exactly what’s needed for the assertion `System.assertEquals(errors.size(), 1);`.</Database.Error>

❌ Why the others are incorrect:
- C: a.errors() is not a valid method for SObject. The correct method is getErrors().
- D: a.containsErrors() does not exist in Apex — it’s an invalid method.

🔗 Documentation:
- SObject.addError()
- SObject.getErrors()
- SObject.hasErrors()

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Handling Validation Errors in Tests

19
Q

Which of the following statements are true about skipping code coverage for an Apex test run in the Developer Console?

Choose 3 answers.

A. Skipping code coverage has no impact on the speed of a test run.
B. No data about Apex test coverage is stored.
C. The Suite Manager can be used to skip code coverage.
D. Faster feedback is received on the pass or fail status of a test run.
E. Code coverage can be skipped during a new test run.

A

✅ B. No data about Apex test coverage is stored.
✅ D. Faster feedback is received on the pass or fail status of a test run.
✅ E. Code coverage can be skipped during a new test run.
🧠 Explanation:
- ✅ B: When you skip code coverage during a test run, Salesforce does not store any code coverage data.
- ✅ D: Skipping coverage speeds up execution, which provides faster feedback on pass/fail results.
- ✅ E: In the Developer Console, there’s an option to skip code coverage when launching a new test run.

❌ Why the others are incorrect:
- A: Skipping code coverage does improve performance, so saying it has no impact is false.
- C: The Suite Manager is used to group test classes, not to skip coverage — that’s done through a checkbox in the Developer Console.

🔗 Documentation:
- Developer Console Test Execution
- Skip Code Coverage Option

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Developer Console Overview

20
Q

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.

A. ‘Apex Classes’ page in Setup
B. ‘Test Manager’ in the Developer Console
C. ‘Apex Test Execution’ page in Setup
D. ‘New Run’ menu item in the Developer Console

A

✅ B. ‘Test Manager’ in the Developer Console
✅ D. ‘New Run’ menu item in the Developer Console
🧠 Explanation:
- ✅ B. Correct: The Test Manager in the Developer Console provides the interface to run tests, and includes an option to skip collecting code coverage.
- ✅ D. Correct: When you select ‘New Run’ in the Developer Console, you can choose to skip code coverage collection by checking the corresponding option.

❌ Why the others are incorrect:
- A: The ‘Apex Classes’ page does not provide test execution or any option related to code coverage.
- C: The ‘Apex Test Execution’ page allows you to run and monitor tests, but you cannot skip code coverage from there.

🔗 Documentation:
- Run Tests in the Developer Console
- Skip Code Coverage Option

📚 Additional Resources:
- Trailhead: Apex Testing
- Salesforce Help: Developer Console Overview

21
Q

How can a developer execute a new test class?

Choose 2 answers.

A. Through the Test menu in the Developer Console
B. Through the Apex Test Execution in the Setup menu
C. Using the REST API and ApexTestRun method
D. By accessing the Run Apex Classes in the Setup menu

A

✅ A. Through the Test menu in the Developer Console
✅ B. Through the Apex Test Execution in the Setup menu
🧠 Explanation:
- ✅ A. Correct: In the Developer Console, you can run test classes using the Test > New Run menu item.
- ✅ B. Correct: From Setup, you can go to Apex Test Execution to schedule or immediately run selected test classes.

❌ Por qué las otras son incorrectas:
- C: While technically valid for automation, the REST API is not typically how a developer manually executes test classes.
- D: The ‘Run Apex’ page is for executing Apex code, not test classes.

🔗 Documentación:
- Run Apex Tests in Developer Console
- Run Apex Tests from Setup

📚 Recursos adicionales:
- Trailhead: Apex Testing
- Salesforce CLI + Apex Test Guide

22
Q

When test data cannot be created programmatically, how can pre-existing data be accessed?

Choose 1 answer.

A. Annotate the test method with [WithSharing=false]
B. Annotate the test class or method with [SeeAllData=true]
C. Annotate the test class or method with [SeeAllData=false]
D. Annotate the test method with [WithSharing=true]

A

✅ B. Annotate the test class or method with [SeeAllData=true]
🧠 Explanation:
- ✅ B. Correct: By default, test methods do not have access to org data. To explicitly allow access to pre-existing records, use the annotation @isTest(SeeAllData=true) on the class or method. This should be used sparingly, only when data cannot be created in the test context (e.g., Pricebook2, Person Accounts, etc.).

❌ Por qué las otras son incorrectas:
- A y D: with sharing and without sharing control record-level access enforcement — not access to org data.
- C: This is actually the default behavior — SeeAllData=false is assumed unless overridden — and it does not allow access to org data.

🔗 Documentación:
- @isTest Annotation and SeeAllData
- Test Data Visibility

📚 Recursos adicionales:
- Trailhead: Apex Testing
- Salesforce Help: SeeAllData Explained

23
Q

Which of the following capabilities are included in the Apex testing framework?

Choose 2 answers.

A. Check test results and code coverage.
B. Use integrated tools to run unit tests.
C. Create test methods automatically.
D. Audit code for security vulnerabilities.

A

✅ A. Check test results and code coverage.
✅ B. Use integrated tools to run unit tests.
🧠 Explanation:
- ✅ A. Correct: The Apex testing framework includes built-in functionality to verify test results and analyze code coverage after test execution.
- ✅ B. Correct: Salesforce provides several integrated tools like the Developer Console, Setup UI, and Salesforce CLI to run unit tests easily.

❌ Por qué las otras son incorrectas:
- C: Test methods must be written manually. The framework does not auto-generate test methods.
- D: Security auditing is not part of the Apex testing framework. That’s handled by other tools like Salesforce Code Analyzer or Checkmarx.

🔗 Documentación:
- Apex Testing Overview
- Apex Code Coverage

📚 Recursos adicionales:
- Trailhead: Apex Testing
- Salesforce Help: Developer Console for Tests

24
Q

A developer is creating an Apex class that will rely heavily on a user’s profile and permission sets to determine which logic path to take. What testing best practices should the developer implement in the unit tests?

Choose 2 answers.

A. Test all conditional paths through the code to maximize coverage
B. Use the seeAllData=true modifier on Apex tests to avoid running into sharing issues
C. Use system.assert() methods to verify that data is created correctly
D. Run tests that result in no more than 10 records being updated at a time

A

✅ A. Test all conditional paths through the code to maximize coverage
✅ C. Use system.assert() methods to verify that data is created correctly
🧠 Explanation:
- ✅ A. Correct: It’s a best practice to test all logical branches to ensure high coverage and validate the behavior of permission- or profile-driven logic.
- ✅ C. Correct: Using System.assert() is essential to verify expected outcomes, such as confirming the correct logic path was taken or that the data is valid.

❌ Por qué las otras son incorrectas:
- B: Using seeAllData=true is discouraged. It breaks test isolation and leads to unreliable results. You should create any required data in the test method.
- D: There is no best practice limiting updates to 10 records in tests. In fact, you should test bulk operations with more than 10 to validate bulk-safe logic.

🔗 Documentación:
- Best Practices for Apex Tests
- System.assert() Method

📚 Recursos adicionales:
- Trailhead: Apex Testing
- Salesforce Help: Unit Test Structure

25
Which of the following is a best practice when writing Apex test classes? Choose 1 answer. A. Use the SeeAllData=true annotation. B. Use the Assert class methods to verify test results. C. Use the System.debug() method to verify test results. D. Use the @future annotation.
✅ B. Use the Assert class methods to verify test results. 🧠 Explanation: - ✅ **B. Correct**: Using methods like `System.assert()`, `System.assertEquals()`, and `System.assertNotEquals()` is a **core best practice** in test classes to validate that logic works as expected. ❌ Por qué las otras son incorrectas: - **A**: `SeeAllData=true` is **discouraged** except in very specific cases, because it makes tests dependent on org data, which reduces reliability. - **C**: `System.debug()` helps with troubleshooting, but **does not validate** anything. It does not fail the test if the logic is wrong. - **D**: `@future` is used to define asynchronous methods, **not for writing test classes**. It's unrelated to test best practices. 🔗 Documentación: - [System.assert Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_system.htm) - [Best Practices for Apex Tests](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Help: Structure and Verify Apex Unit Tests](https://help.salesforce.com/s/articleView?id=sf.code_bestpractices_tests.htm&type=5)
26
To meet a new requirement, a developer has added new methods in several Apex classes in a Developer sandbox org. Upon deploying to production using the Default test option, a code coverage error was encountered. What can the developer do to successfully deploy the components? Choose 1 answer. A. Run specified tests only to ignore the code coverage requirement. B. Update the respective Apex test classes in the sandbox org. C. Validate the change set first before running the deployment. D. Run the Quick Deploy option if the change set has less than 10 components.
✅ B. Update the respective Apex test classes in the sandbox org. 🧠 Explanation: - ✅ **B. Correct**: If a **code coverage error** is encountered during deployment, the most effective solution is to **write or update unit tests** to cover the new logic added. Code coverage must be at least **75% overall**, and **every class and trigger** must be covered by at least 1 test. ❌ Por qué las otras no son correctas: - **A**: You **cannot bypass** coverage requirements by running only specific tests — Salesforce still enforces overall code coverage. - **C**: Validation runs the deployment in a dry-run mode, but **does not solve** the code coverage issue. - **D**: Quick Deploy can only be used **after a successful validation** — it doesn’t affect coverage or skip tests. 🔗 Documentación: - [Code Coverage Requirements](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm) - [Deploy Components with Change Sets](https://help.salesforce.com/s/articleView?id=sf.changesets_deployment_tips.htm&type=5) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Help Article: Deployment Fails Due to Code Coverage](https://help.salesforce.com/s/articleView?id=000335222&type=1)
27
A developer needs to create pricebook entries with a standard price when creating test data in a unit test. Which of the following is true regarding this use case? Choose 1 answer. A. The standard price book ID is available as a global variable B. The Test.getStandardPriceBookId() method can be used to return the ID of the standard price book C. The standard price book ID should be queried using SOQL D. The unit test needs to be annotated with @isTest(SeeAllData=true) to retrieve the standard price book ID
✅ B. The Test.getStandardPriceBookId() method can be used to return the ID of the standard price book 🧠 Explanation: - ✅ **B. Correct**: In test context, to use the **standard price book**, Salesforce provides the method `Test.getStandardPricebookId()`, which returns its ID even when `SeeAllData=false`. ❌ Por qué las otras no son correctas: - **A**: No existe una variable global que exponga directamente el ID del standard price book. - **C**: No puedes hacer SOQL sobre el standard price book si estás en un contexto de test sin `SeeAllData=true`. - **D**: No necesitas `SeeAllData=true` si usas `Test.getStandardPricebookId()` — ese es precisamente su propósito. 🔗 Documentación: - [Test.getStandardPricebookId()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Test.htm#apex_System_Test_getStandardPricebookId) - [Working with Pricebooks in Apex Tests](https://developer.salesforce.com/forums/?id=906F00000008zrLIAQ) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Help: Pricebook Test Data](https://help.salesforce.com/s/articleView?id=sf.code_test_classes_pricebooks.htm&type=5)
28
Bright Starts company uses the Lead object and a custom object called, 'Sub Lead,' to relate child records to a lead. A custom checkbox field called 'Lead Verified' has been created on both objects. The developer has configured a process that runs when a Sub Lead record is updated and invokes a flow if its 'Lead Verified' field is ticked. The invoked flow sets the 'Lead Verified' checkbox to true on the parent record only if all of the related Sub Leads have been marked as verified. What are the considerations when writing a test class for the flow in this scenario? Choose 3 answers. A. Ensure that a Sub Lead record has the 'Lead Verified' field set to true in the test class to invoke the flow. B. Use assertion methods such as 'assertEquals' to verify that the flow produces expected results. C. Create both positive and negative test cases to ensure the flow properly works in the test class. D. See to it that a Lead record has the 'Lead Verified' field set to true in the test class to invoke the flow. E. Utilize the 'FlowTestCoverage' object to cover the flow's positive test cases in the test class.
✅ A. Ensure that a Sub Lead record has the 'Lead Verified' field set to true in the test class to invoke the flow. ✅ B. Use assertion methods such as 'assertEquals' to verify that the flow produces expected results. ✅ C. Create both positive and negative test cases to ensure the flow properly works in the test class. 🧠 Explanation: - ✅ **A. Correct**: To trigger the flow in the test context, you must create a Sub Lead record and mark its **'Lead Verified' = true**. - ✅ **B. Correct**: Using `System.assertEquals()` or similar assertions is a **best practice** to confirm expected outcomes of flow logic in test classes. - ✅ **C. Correct**: Writing **both positive and negative test cases** ensures the flow logic handles all scenarios as expected and maximizes code coverage. ❌ Por qué las otras son incorrectas: - **D**: The Lead's **'Lead Verified'** field should be set **by the flow**, not manually in the test. - **E**: The `FlowTestCoverage` object is not a real or supported construct in Apex — **not a valid tool** for unit testing flows. 🔗 Documentación: - [Testing Flows with Apex](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_flow_tests.htm) - [Best Practices for Flow Testing](https://help.salesforce.com/s/articleView?id=sf.flow_testing.htm&type=5) 📚 Recursos adicionales: - [Trailhead: Automate Processes with Flow](https://trailhead.salesforce.com/content/learn/modules/flow-builder) - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing)
29
How can test data be supplied to test methods? Choose 3 answers. A. The Data Import Wizard can be used in test mode. B. Data can be loaded from a .csv file using Data Loader. C. Data can be created programmatically using Apex. D. Existing data can be accessed using SOQL queries. E. Data can be loaded from static resources.
✅ C. Data can be created programmatically using Apex. ✅ D. Existing data can be accessed using SOQL queries. ✅ E. Data can be loaded from static resources. 🧠 Explanation: - ✅ **C. Correct**: Best practice in Apex tests is to create test data programmatically using DML statements. - ✅ **D. Correct**: Test methods can query **existing data** only if the method is annotated with `@isTest(SeeAllData=true)`. - ✅ **E. Correct**: Static resources (like `.csv` files) can be used in conjunction with `Test.loadData()` to populate data in test methods. ❌ Why the other options are incorrect: - **A**: The **Data Import Wizard** is a UI tool and cannot be used in test context or from Apex tests. - **B**: **Data Loader** is also external and runs outside the Apex test execution — it's not usable in test methods. 🔗 Documentación: - [Test.loadData()](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_test.htm#apex_System_Test_loadData) - [Testing Data Access](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data_access.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Create Test Data with Static Resources](https://developer.salesforce.com/forums/?id=906F0000000kEKVIA2)
30
Which of the following can be used to execute specific Apex test methods in an organization? Choose 2 answers. A. Data Loader, SOAP API B. Developer Console, Visual Studio Code C. Change Sets, Developer Console D. Code Builder, SOAP API
✅ B. Developer Console, Visual Studio Code ✅ D. Code Builder, SOAP API 🧠 Explanation: - ✅ **B. Correct**: You can run specific test methods from both the **Developer Console** (via Test > New Run) and **Visual Studio Code** using the Salesforce CLI or test runners. - ✅ **D. Correct**: **Code Builder** is a cloud-based IDE that allows test execution, and **SOAP API** (via `runTests()` method) also supports executing specific test methods programmatically. ❌ Why the others are incorrect: - **A**: Data Loader is **not** used to run Apex tests — it's for data import/export. - **C**: Change Sets do **not provide** a mechanism to run specific Apex tests; they are used for deployment. 🔗 Documentación: - [Run Apex Tests with Developer Console](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_dev_console.htm) - [SOAP API: runTests()](https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/intro_run_tests.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Code Builder Overview](https://developer.salesforce.com/docs/platform/code-builder/overview) - [VS Code Extension Pack for Salesforce](https://developer.salesforce.com/tools/vscode)
31
Private methods are defined in a certain Apex class. A developer is creating unit tests and needs to access these methods. How can this be accomplished? Choose 1 answer. A. Annotate the private methods with @TestVisible B. Change the access modifier of the class that private methods are contained into public C. Change the access modifier of the private methods to public D. Annotate the class that the private methods are contained in with @TestVisible
✅ A. Annotate the private methods with @TestVisible 🧠 Explanation: - ✅ **A. Correct**: The `@TestVisible` annotation allows test methods to access **private or protected methods and variables**. This is the preferred way to keep encapsulation intact while enabling test access. ❌ Why the others are incorrect: - **B**: Changing the class’s access modifier doesn’t affect access to **private methods**. - **C**: Making private methods public just for testing **violates encapsulation** — it’s not best practice. - **D**: `@TestVisible` must be applied to **individual members**, not to the entire class. 🔗 Documentación: - [@TestVisible Annotation](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Best Practices: Unit Tests](https://developer.salesforce.com/blogs/2020/03/testing-in-salesforce-why-how-and-best-practices)
32
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. A. @testVisible B. @testMethod C. @isTest D. @testSetup
✅ A. @testVisible 🧠 Explanation: - ✅ **A. Correct**: The `@TestVisible` annotation makes **private or protected methods or variables accessible** to test classes. This allows test classes to verify internal logic **without changing access modifiers**. ❌ Why the others are incorrect: - **B**: `@testMethod` is used to define test methods (in legacy syntax), not to expose private methods. - **C**: `@isTest` marks a class or method as a test, but **does not grant visibility** to private members. - **D**: `@testSetup` is for methods that set up data before test methods run, and **not for accessing private methods**. 🔗 Documentación: - [@TestVisible](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm) - [Apex Testing Visibility Rules](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Help: Unit Test Visibility](https://help.salesforce.com/s/articleView?id=sf.code_testvisible_annotation.htm&type=5)
33
Bright Starts company has created a lookup relationship between the Lead object and a child 'Sub Lead' custom object for their lead verification process. Both objects have a 'Verified' custom checkbox field that is used for marking a lead or a sub lead as verified or not. In addition, a process is used to automatically mark a parent lead as verified if the 'Verified' field of any of its existing sub leads is updated to true. How can this process be tested efficiently using Apex tests? Choose 3 answers. A. Ensure the test class considers a bulk update of Sub Lead records to determine potential issues with governor limits. B. Use 'assert' methods in the test class to verify the expected outcome of the process, for all positive and negative test cases. C. Query the 'FlowTestCoverage' object in the test class to test the process during the Apex test execution. D. Update a Sub Lead test record in the test class by changing the 'Verified' checkbox to true, to invoke the process during Apex test execution. E. Insert a Sub Lead test record in the test class with the 'Verified' checkbox marked true, to invoke the process during Apex test execution.
✅ B. Use 'assert' methods in the test class to verify the expected outcome of the process, for all positive and negative test cases. ✅ C. Query the 'FlowTestCoverage' object in the test class to test the process during the Apex test execution. ✅ D. Update a Sub Lead test record in the test class by changing the 'Verified' checkbox to true, to invoke the process during Apex test execution. 🧠 Explanation: - ✅ **B. Correct**: Assertions (`System.assert()`, `assertEquals()`) are a best practice to validate whether the flow/process achieved the expected result. - ✅ **C. Correct**: As of newer platform capabilities, **FlowTestCoverage** provides programmatic access to flow coverage and can be queried during test execution. - ✅ **D. Correct**: The process is triggered on update, so changing the 'Verified' field from false to true in a test simulates the trigger condition correctly. ❌ Incorrectas: - **A**: Although testing bulk scenarios is good practice, it is **not directly necessary** to verify the functioning of this specific automation logic. - **E**: The process is invoked on **update**, not on insert — inserting with the checkbox checked will **not trigger** the flow/process. 🔗 Documentación: - [FlowTestCoverage Class (Pilot)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_FlowTestCoverage.htm) - [Apex Tests for Flows](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_flow_tests.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Trailhead: Automate Processes with Flow](https://trailhead.salesforce.com/content/learn/modules/flow-builder)
34
Which of the following are true regarding test coverage calculation in Apex? Choose 2 answers. A. Only executable lines are included. B. Multiple statements on one line are counted separately. C. Comments are not included. D. Blank lines are counted.
✅ A. Only executable lines are included. ✅ C. Comments are not included. 🧠 Explanation: - ✅ **A. Correct**: Code coverage in Apex counts **only executable lines**, such as method calls, logic (if/else), and DML operations. - ✅ **C. Correct**: **Comments are ignored** by the compiler and are not part of coverage calculation. ❌ Incorrectas: - **B**: Multiple statements on the same line are **not split for coverage**. The line is either covered or not. - **D**: Blank lines are **not counted**, as they do not represent executable logic. 🔗 Documentación: - [Apex Code Coverage](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_intro.htm) - [Run Tests and View Code Coverage](https://developer.salesforce.com/docs/atlas.en-us.234.0.apexcode.meta/apexcode/apex_testing_coverage_display.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Video: Code Coverage in Salesforce](https://www.youtube.com/watch?v=O0hJ2TDffT8)
35
Which of the following are true when using Test Setup methods? Choose 2 answers. A. Test Setup methods are prefixed with the @SetupForTest annotation. B. A Test Setup method is used to create test records once and then access them in every test method in the test class. C. The testing framework executes the test setup method last and after any test method in the class. D. Any changes to the records created in the @testSetup method are rolled back after each test method finishes execution.
✅ B. A Test Setup method is used to create test records once and then access them in every test method in the test class. ✅ D. Any changes to the records created in the @testSetup method are rolled back after each test method finishes execution. 🧠 Explanation: - ✅ **B. Correct**: The `@testSetup` annotation is used to create **common test data** that can be shared across all test methods in the class. The setup runs **once per class**. - ✅ **D. Correct**: Like any test context in Apex, the database changes from `@testSetup` are **rolled back automatically** after each test method runs. ❌ Incorrectas: - **A**: The correct annotation is `@testSetup`, not `@SetupForTest`. - **C**: The `@testSetup` method is executed **before** any test methods — not last. 🔗 Documentación: - [@testSetup Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testsetup.htm) - [Creating Test Data Using testSetup](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_data.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Help: Use Test Setup Methods](https://help.salesforce.com/s/articleView?id=sf.code_test_methods_testsetup.htm&type=5)
36
A developer is building a unit test to validate the behavior of a new Apex method. The expected output of the method should not be null and be equal to a predefined value. If the variable 'output' represents the output returned by the Apex method and 'value' represents the predefined value, which of the following options can be used as assertions in the unit test? Choose 2 answers. A. Assert.isNotNull(output); B. System.isEqual(value, output); C. Assert.areEqual(value, output); D. System.isNotNull(value);
✅ A. Assert.isNotNull(output); ✅ C. Assert.areEqual(value, output); 🧠 Explanation: - ✅ **A. Correct**: `Assert.isNotNull(output)` ensures that the returned value from the method is not null — this is a key part of verifying expected functionality in unit tests. - ✅ **C. Correct**: `Assert.areEqual(expected, actual)` is a valid assertion in Apex to compare values. This helps verify the method returned the correct predefined result. ❌ Incorrectas: - **B**: `System.isEqual()` is **not a valid method** in Apex. The proper way to assert equality is `System.assertEquals()` or `Assert.areEqual()`. - **D**: Asserting that a predefined value is not null is not useful in this context, since the focus is on testing the method output. 🔗 Documentación: - [System.Assert Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Assert.htm) - [Apex Unit Test Assertions](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_unit_tests_assertions.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Apex Developer Guide: Writing Effective Unit Tests](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm)
37
Before code can be deployed to production, which of the following must be true? Choose 2 answers. A. All classes and triggers must compile successfully B. At least 75% of Apex code must be covered by unit tests C. Test methods and test classes must be counted as part of code coverage D. At least 75% of Apex code in triggers must be covered by unit tests
✅ A. All classes and triggers must compile successfully ✅ B. At least 75% of Apex code must be covered by unit tests 🧠 Explanation: - ✅ **A. Correct**: Salesforce requires that all code (classes and triggers) compiles without errors before deployment to production. - ✅ **B. Correct**: The platform enforces a **minimum of 75% code coverage** for all Apex code (not just triggers) before allowing deployment to production. Also, all triggers must be covered by **some** test. ❌ Incorrectas: - **C**: Test methods and test classes **are excluded** from code coverage calculations. - **D**: While it's true that **triggers must be covered**, the 75% requirement applies to **all Apex code**, not separately to just triggers. 🔗 Documentación oficial: - [Deploy Code to Production](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_deploying_ant.htm) - [Code Coverage Requirements](https://help.salesforce.com/s/articleView?id=sf.code_dev_console_tests_coverage.htm&type=5) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Help: Code Coverage and Deployment](https://help.salesforce.com/s/articleView?id=sf.code_requirements.htm&type=5)
38
A developer needs to deploy an Apex class and its test class to a production org but has limited time. She has decided to run selected tests. Which of the following are true about running selected tests? Choose 2 answers. A. Code coverage is computed for each class and trigger individually and is different than the overall coverage percentage. B. Running selected or specified tests is only available in Metadata API. C. Individual test methods can also be specified. D. If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails.
✅ C. Individual test methods can also be specified. ✅ D. If the code coverage of an Apex component in the deployment is less than 75%, the deployment fails. 🧠 Explanation: - ✅ **C. Correct**: When running **specified tests** during deployment, it is possible to define **specific test methods**, not just entire classes, using tools like Metadata API or SFDX. - ✅ **D. Correct**: When using the **Run Specified Tests** option, Salesforce still enforces the 75% overall coverage rule, and each component included in the deployment must **not fail coverage validation**. ❌ Incorrectas: - **A**: This is misleading. While code coverage is tracked per class/trigger, **deployment validation checks overall and per-class coverage depending on settings**, not just the difference between them. - **B**: Running specified tests is available through **multiple interfaces**, including **Change Sets**, **SFDX**, and **Ant**, not just Metadata API. 🔗 Documentación: - [Salesforce Help: Deployment Test Options](https://help.salesforce.com/s/articleView?id=sf.deploy_tests_options.htm) - [Apex Test Classes and Deployment](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_deploy_test.htm) 📚 Recursos adicionales: - [Trailhead: Deploying Apex](https://trailhead.salesforce.com/content/learn/modules/apex_testing/apex_testing_deployment) - [Salesforce Developer Guide: Run Specified Tests](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_deploy_tests.htm)
39
What options are available to run unit tests in an org? Choose 3 answers. A. Run all test methods in a test class B. Run all tests that were successful only C. Run a test suite D. Run all non-test methods in a test class E. Run all unit tests in an org
✅ A. Run all test methods in a test class ✅ C. Run a test suite ✅ E. Run all unit tests in an org 🧠 Explanation: - ✅ **A. Correct**: You can run all test methods within a specific test class — this is common using Developer Console, Setup, VS Code, or SFDX. - ✅ **C. Correct**: Salesforce allows you to create **Test Suites** — collections of test classes — and run them together for efficient testing. - ✅ **E. Correct**: There is a “Run All” option that executes **all unit tests** in an org, useful for validation before production deployments. ❌ Incorrectas: - **B**: You cannot run “only successful tests.” There is no such filter in Salesforce — you may rerun **failed tests**, but not successful ones exclusively. - **D**: Only methods annotated with `@isTest` are recognized as test methods. **Non-test methods** will **not run** via testing tools. 🔗 Documentación: - [Running Tests in Developer Console](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_console.htm) - [Organize Tests with Test Suites](https://help.salesforce.com/s/articleView?id=sf.code_test_suites.htm) 📚 Recursos adicionales: - [Trailhead: Apex Testing](https://trailhead.salesforce.com/content/learn/modules/apex_testing) - [Salesforce Help: Run Tests](https://help.salesforce.com/s/articleView?id=sf.code_testing_running.htm)