Salesforce-Platform-Developer-II Exam Questions With Explanations

The best unofficial Salesforce-Platform-Developer-II exam questions with research based explanations of each question will help you Prepare & Pass the exam for FREE!

Over 15K Students have given a five star review to SalesforceKing

Why choose our Practice Test

By familiarizing yourself with the Salesforce-Platform-Developer-II exam format and question types, you can reduce test-day anxiety and improve your overall performance.

Up-to-date Content

Ensure you're studying with the latest exam objectives and content.

Unlimited Retakes

We offer unlimited retakes, ensuring you'll prepare each questions properly.

Realistic Exam Questions

Experience exam-like questions designed to mirror the actual Salesforce-Platform-Developer-II test.

Targeted Learning

Detailed explanations help you understand the reasoning behind correct and incorrect answers.

Increased Confidence

The more you practice, the more confident you will become in your knowledge to pass the exam.

Study whenever you want, from any place in the world.

Salesforce Salesforce-Platform-Developer-II Exam Sample Questions 2025

Start practicing today and take the fast track to becoming Salesforce Salesforce-Platform-Developer-II certified.

22024 already prepared
Salesforce Spring 25 Release
202 Questions
4.9/5.0

Consider the following code snippet:

A. Option A

B. Option B

C. Option C

D. Option D

A.   Option A

Explanation:

📌 Why A is Correct
The issue lies in test execution context and sharing rules. When the test method runs, it executes in the context of the default test user (a system context user), not the intended “Standard User” (user2). The method AccountController.getAllAccounts() performs a SOQL query that’s affected by the sharing rules of the user executing the query.
In Salesforce, when using with sharing in an Apex class (as seen in AccountController), the query obeys object-level sharing rules. Therefore, the number of records returned by getAllAccounts() depends on what records the current user can access.
In the test, you create 20 records assigned to user2, but unless you run the query as user2, your test won't see them — hence the assertion fails (result.size() ≠ 20).

🔁 How to Fix It:
→ Use System.runAs(user2) to simulate the Standard User.
→ Enclose the logic inside Test.startTest() and Test.stopTest() to ensure the governor limits are reset and asynchronous operations (if any) are executed in a controlled context.

📘 Updated Code Snippet (Conceptually):
System.runAs(user2) {
Test.startTest();
List result = AccountController.getAllAccounts();
Test.stopTest();
System.assertEquals(20, result.size());
}

This will correctly simulate user2’s context, and since all 20 accounts were inserted with user2's ownership, the query returns them.

❌ Why Other Options Are Incorrect

B — Add System.runAs(user1) and Test.startTest()

🔴 Why it's wrong:
→ Using user1, the System Administrator, would cause the controller to return all accounts — but your test specifically created 20 accounts tied to user2 (Standard User). Using user1 would not assert the intended user access model and defeats the purpose of testing sharing-based logic.

C — Query the Administrator and enclose lines 15–16 within System.runAs(user1)

🔴 Why it's wrong:
→ Running the test as a System Administrator means full access to all data, regardless of sharing rules. This doesn’t reflect the actual permissions of a Standard User and therefore doesn’t verify sharing behavior, which is the goal of this test.

D — Query Standard User into memory and use System.runAs(user2) in a @testSetup method

🟡 Partially valid idea, but:
→ You cannot use System.runAs() inside @testSetup methods — it will throw an error. According to Salesforce documentation, System.runAs() is only allowed inside test methods, not setup blocks.
→ The test data (like user2) should be created in @testSetup, but context simulation (System.runAs) must be handled in the test method itself.

Reference:
Using the runAs Method
Testing Best Practices

Universal Containers uses Salesforce to track orders in an order__c object. The order = object has private organization-wide defaults. The order = object has a custom field, Quality_Controller_c, that is a Lookup to User and is used to indicate that the specified User is performing quality control on the order_ co. What should be used to automatically give read only access to the User set in the Quality_Controller field?

A. Record ownership

B. Criteria-based sharing

C. Apex managed sharing

D. User managed sharing

C.   Apex managed sharing

Explanation:

To address the requirement of automatically granting read-only access to the user specified in the Quality_Controller__c field on the order__c object, we need to consider the Salesforce sharing model and the tools available. The order__c object has private organization-wide defaults, meaning records are only accessible to the record owner and users with higher roles in the hierarchy (if enabled), unless additional sharing is configured. The Quality_Controller__c field is a Lookup to the User object, identifying the individual responsible for quality control, and this user needs automatic read-only access to the corresponding order record.

Let’s evaluate the provided options:

A. Record Ownership
Record ownership in Salesforce assigns a user as the owner of a record, granting them full access by default (e.g., read, edit, delete, and sharing capabilities, depending on their profile and role). The requirement, however, specifies read-only access for the user in the Quality_Controller__c field, not full control. Additionally, ownership is typically a single user assigned to the record, not a mechanism to grant access based on a separate lookup field. Making the Quality_Controller__c user the owner would both exceed the required access level and fail to align with the intent of indicating a quality control role rather than ownership. Thus, record ownership is not suitable.

B. Criteria-Based Sharing
Criteria-based sharing rules in Salesforce allow records to be shared with users, roles, or groups based on field values or record ownership. For example, we could create a rule like "Share order__c records where Quality_Controller__c is not null," but the challenge lies in specifying who to share with. Criteria-based sharing typically shares records with predefined recipients, such as a role, group, or all internal users, not dynamically with the specific user referenced in a lookup field like Quality_Controller__c. While we can use criteria to identify which records to share (e.g., based on the presence of a value in Quality_Controller__c), Salesforce’s declarative sharing rules do not support dynamically targeting the user specified in that field as the recipient. This limitation makes criteria-based sharing insufficient for automatically granting access to the exact user in the lookup field.

C. Apex Managed Sharing
Apex managed sharing allows programmatic control over record access by creating sharing records via Apex code. In this scenario, we can use an Apex trigger on the order__c object to detect changes to the Quality_Controller__c field (on insert or update) and create a corresponding order__Share record. This sharing record would specify:

✔ ParentId: The ID of the order__c record.
✔ UserOrGroupId: The ID of the user in the Quality_Controller__c field.
✔ AccessLevel: Set to "Read" for read-only access.
✔ RowCause: A custom sharing reason (e.g., "Quality_Control__c") to track the purpose of the share.

For example, a basic trigger might look like this:
This approach automates the process: whenever the Quality_Controller__c field is populated or updated, the trigger ensures the specified user gains read-only access. It also allows for cleanup logic (e.g., deleting old sharing records if the field changes or is cleared), ensuring access remains aligned with the field value. Given the need for dynamic, field-specific sharing, Apex managed sharing is a viable and appropriate solution.

D. User Managed Sharing
User managed sharing, also known as manual sharing, allows users with sufficient permissions (e.g., "Manage Sharing" on their profile) to manually share a record with other users or groups, specifying the access level (e.g., read-only). However, this process requires human intervention for each record, either by the record owner or an administrator. The requirement emphasizes automatic access, which manual sharing cannot provide, as it depends on someone explicitly sharing the record each time the Quality_Controller__c field is set or changed. This makes user managed sharing impractical due to its lack of automation and potential for inconsistency.

Conclusion:
The goal is to automatically grant read-only access to the user in the Quality_Controller__c field. Record ownership (A) provides too much access and isn’t field-driven. Criteria-based sharing (B) cannot dynamically target the user in a lookup field. User managed sharing (D) is manual, not automatic. Apex managed sharing (C), however, offers the flexibility to programmatically create sharing records based on the Quality_Controller__c field value, meeting both the automation and access-level requirements. While declarative solutions like Flow or Process Builder might seem appealing, they cannot directly create sharing records, leaving Apex as the most effective approach for this custom object scenario.
Thus, the best solution is C. Apex managed sharing.

Which method should be used to convert a Date to a String in the current user's locale?

A. String.format

B. Date.paras

C. Date. format

D. String.valueof

C.   Date. format

Explanation:

To determine the method that should be used to convert a Date to a String in the current user's locale, we need to evaluate the available Apex methods based on their functionality and alignment with Salesforce's localization features. The solution must account for the user's locale settings (e.g., date format preferences like MM/dd/yyyy or dd/MM/yyyy) to ensure the output string reflects the appropriate regional format. Let’s assess the options.

Evaluation of Options:

A. String.format
The String.format() method formats a string using a pattern and arguments, often with locale-specific formatting when combined with MessageFormat. However, it is primarily designed for general string formatting and requires a specific format string (e.g., {0,date,short}) to handle dates, which must be manually defined. It does not automatically adapt to the current user's locale unless explicitly configured with locale data, making it less optimal for this requirement.

B. Date.parse
The Date.parse() method converts a String in a locale-specific format (e.g., based on the user's locale) into a Date object. This is the reverse of the required operation (converting a Date to a String), so it is not applicable. This option is incorrect.

C. Date.format
The Date.format() method converts a Date object to a String using the locale of the current user. It automatically applies the user's locale settings (e.g., language and date format) to determine the output format (e.g., "MM/dd/yyyy" for en_US or "dd/MM/yyyy" for en_GB). This method is specifically designed for this purpose and requires no additional configuration, making it the most suitable choice.

D. String.valueOf
The String.valueOf() method converts various data types, including Date, to a String. However, it uses a default format (typically ISO-like, e.g., "2025-08-06") that does not adapt to the current user's locale. While it can be used, it lacks the locale-specific formatting provided by Date.format(), making it less optimal for this requirement.

Correct Answer: C. Date.format
The Date.format() method is the recommended approach to convert a Date to a String in the current user's locale. It leverages Salesforce's localization framework to automatically apply the user's locale settings, ensuring the output matches regional date format preferences without manual intervention. This aligns with the Salesforce Platform Developer II exam’s “Apex Programming” domain, emphasizing locale-aware programming.

Reference: Salesforce Apex Developer Guide - Date Class.

Additional Notes: To use Date.format(), simply call it on a Date object (e.g., Date.today().format()), and it will return a String in the user's locale (e.g., "08/06/2025" for en_US). If a specific format is needed, Date.format(String format) can be used with a custom pattern (e.g., Date.today().format('yyyy-MM-dd')), but the default behavior suffices for locale adaptation. This method is efficient and aligns with user experience best practices in Salesforce.

Universal Containers implements a private sharing model for the Convention Attendee co custom object. As part of a new quality assurance effort, the company created an Event_Reviewer_c user lookup field on the object. Management wants the event reviewer to automatically gain ReadWrite access to every record they are assigned to. What is the best approach to ensure the assigned reviewer obtains Read/Write access to the record?

A. Create a before insert trigger on the Convention Attendee custom object, and use Apex Sharing Reasons and Apex Managed Sharing.

B. Create an after insert trigger on the Convention Attendee custom object, and use Apex Sharing Reasons and Apex Managed Sharing.

C. Create criteria-based sharing rules on the Convention Attendee custom object to share the records with the Event Reviewers.

D. Create a criteria-based sharing rule on the Convention Attendee custom object to share the records with a group of Event Reviewers.

B.   Create an after insert trigger on the Convention Attendee custom object, and use Apex Sharing Reasons and Apex Managed Sharing.

Explanation:

✅ Correct Answer: B — After insert trigger with Apex Sharing Reasons and Managed Sharing
🔐 Why this works:
When implementing Apex Managed Sharing, Salesforce requires that the record already exist in the database so it has a valid record ID. This ID is necessary for creating a custom Share record that links the record to the user in the Event_Reviewer__c field. Because of this, the logic to share the record must happen after the insert — which is why the correct place is an after insert trigger.

🛠 Managed Sharing gives full control over access logic in Apex. By using a custom Apex Sharing Reason, you can apply named reasons for the share (e.g., “Assigned Reviewer Access”), and admins can later manage them through the UI if needed. This also keeps sharing logic dynamic and scalable, suitable for future changes.

📚 Use Case Fit:
This solution supports the requirement that access is automatically granted when a user is assigned as a reviewer. It works with private sharing models, ensures proper access is granted without compromising security, and is admin-friendly due to its maintainability.

❌ A — Before insert trigger with Apex Managed Sharing
🚫 Why it's wrong:
In a before insert trigger, the record does not yet have a Salesforce ID, which is essential to create a valid Share object in Apex. Since Apex Managed Sharing requires the ParentId (record ID) to associate the shared record to the target user, this method fails technically. The trigger would attempt to share a record that doesn’t yet exist — leading to runtime errors or unintended behavior.

💡 Key Concept:
Sharing must occur after the database transaction, which makes this a clear architectural limitation of before triggers.

❌ C — Criteria-based sharing rule for Event Reviewers
🚫 Why it's wrong:
Criteria-based sharing rules can only apply access based on record field values — not based on dynamic user lookups like Event_Reviewer__c. You can’t configure them to assign access directly to the user listed in a lookup field. They also only support role, group, or public access, not individual user-based field references.

⚠️ Limitation:
They are designed for bulk sharing to groups of users, not one-to-one sharing based on lookup assignments. Therefore, they can’t fulfill the requirement to grant access dynamically to the user assigned.

❌ D — Share with a group of Event Reviewers
🚫 Why it's wrong:
This would share every Convention Attendee record with a static group of users, regardless of who is assigned as Event_Reviewer__c. This does not meet the requirement of only granting access to the specific assigned reviewer. Also, if reviewers change or rotate frequently, managing group membership would become cumbersome and error-prone.

📉 Problem:
It lacks flexibility, introduces overhead, and fails to dynamically reflect the lookup field changes.

Reference:
Apex Managed Sharing

What are three reasons that a developer should write Jest tests for Lightning web components?
(Choose 3 answers)

A. To test a component's non-public properties.

B. To test basic user interaction

C. To verify the DOM output of a component

D. To test how multiple components work together

E. To verify that events fire when expected

B.   To test basic user interaction
C.   To verify the DOM output of a component
E.   To verify that events fire when expected

Explanation:

Writing Jest tests for Lightning Web Components (LWCs) is a critical practice in Salesforce development to ensure code quality, functionality, and reliability. Jest, a JavaScript testing framework, is integrated into the Salesforce LWC development environment to facilitate unit testing. The goal is to validate component behavior, interactions, and output while adhering to best practices. Let's evaluate each option to identify the three most valid reasons for writing Jest tests for LWCs.

Correct Answer:
B. To test basic user interaction
Testing basic user interaction with Jest ensures that a Lightning Web Component responds correctly to user actions such as clicks, inputs, or form submissions. By simulating these interactions (e.g., using fireEvent or triggerEvent), developers can verify that the component's logic executes as intended. This is crucial for user-facing components, as it confirms the UI behaves predictably, enhancing user experience. For the Platform Developer II exam, understanding how to test interactivity is key, making this a primary reason to use Jest in LWC development.

C. To verify the DOM output of a component
Verifying the DOM output of a component with Jest allows developers to ensure the rendered HTML matches the expected structure and content. Using tools like @salesforce/sfdx-lwc-jest and utilities such as createElement, developers can render components and assert against the DOM using query selectors. This is essential for validating visual elements, accessibility, and layout, which are critical for LWC reliability. This testing approach aligns with Salesforce best practices and is a fundamental reason to write Jest tests for LWCs.

E. To verify that events fire when expected
Verifying that events fire when expected is a vital reason to write Jest tests, as LWCs often rely on custom events for communication between components. By testing event emission and handling (e.g., using dispatchEvent and event listeners), developers can ensure the component's event-driven logic works correctly. This is particularly important in complex applications where event propagation impacts functionality. For the Platform Developer II exam, mastering event testing with Jest is a key skill, making it a significant justification for testing.

Incorrect Answer:

Option A: To test a component's non-public properties
Testing a component's non-public properties (e.g., private fields or methods) is generally not a recommended reason to write Jest tests for LWCs. Salesforce encourages testing public APIs and observable behavior rather than internal implementation details, as non-public properties can change without notice. Jest tests should focus on the component's external interface and functionality, not its private state. While technically possible, this approach violates encapsulation principles and is not a primary goal, making it less relevant for the Platform Developer II exam context.

Option D: To test how multiple components work together
Testing how multiple components work together is more suited to integration testing rather than unit testing with Jest. Jest is designed for unit testing individual LWCs in isolation, using mocks or stubs for dependencies. Testing component interactions typically requires a higher-level testing framework or manual testing in a sandbox, as Jest lacks built-in support for end-to-end scenarios. While important, this is outside the scope of Jest's primary purpose for LWCs, making it an incorrect focus for this question.

Reference:

Test Lightning Web Components

Prep Smart, Pass Easy Your Success Starts Here!

Transform Your Test Prep with Realistic Salesforce-Platform-Developer-II Exam Questions That Build Confidence and Drive Success!