Salesforce-Platform-Developer-II Practice Test

Salesforce Spring 25 Release -
Updated On 18-Sep-2025

202 Questions

A developer wrote a trigger on Opportunity that will update a custom Last Sold Date field on the Opportunity's Account whenever an Opportunity is closed. In the test class for the trigger, the assertion to validate the Last Sold Date field fails. What might be causing the failed assertion?

A. The test class has not defined an Account owner when inserting the test data.

B. The test class has not implemented seealldata=true in the test method.

C. The test class has not re-queried the Account record after updating the Opportunity.

D. The test class is not using System. runs () to run tests as a Salesforce administrator.

C.   The test class has not re-queried the Account record after updating the Opportunity.

Explanation:

To understand why the assertion fails in this trigger test scenario, we need to focus on how data is handled in Apex tests, especially regarding trigger behavior and record state in memory vs. the database.

✅ Correct Answer: C. The test class has not re-queried the Account record after updating the Opportunity.

✅ Explanation:
When you update a record in Apex (like an Opportunity), any related changes made by triggers (like updating a field on the parent Account) occur in the database. However, the in-memory version of the Account (from earlier in the test method) does not automatically reflect those changes.
So, if your trigger updates the Last_Sold_Date__c field on Account when an Opportunity is closed, but the test class does not perform a fresh SOQL query to retrieve the updated Account, then any assertion against that field will still reflect the old value (likely null) — causing the test to fail.

✅ Proper fix in the test class:
Account acct = [SELECT Id, Last_Sold_Date__c FROM Account WHERE Id = :accountId];
System.assertEquals(expectedDate, acct.Last_Sold_Date__c);

🔗 Reference: Salesforce Developer Docs – Testing Triggers

❌ A. The test class has not defined an Account owner when inserting the test data.
This is not necessary unless your trigger or validation rules explicitly depend on OwnerId. Salesforce assigns a default owner (usually the running user) if none is provided. So this won’t affect the Last_Sold_Date__c update unless additional logic is involved (not mentioned here).

❌ B. The test class has not implemented seeAllData=true in the test method.
Using seeAllData=true is discouraged and unnecessary here. Since you're inserting test Account and Opportunity records within the test method, no real org data is required. The test should work with only mock/test data.

❌ D. The test class is not using System.runAs() to run tests as a Salesforce administrator.
System.runAs() is used to test behavior under different user roles or profiles (e.g., field-level security or sharing rules). It is not required for triggers to function unless access issues are part of the logic. Again, this isn’t relevant in the scenario described.

✅ Final Verdict:
C. The test class has not re-queried the Account record after updating the Opportunity is the correct answer because without re-querying, the test accesses stale data, leading to a failed assertion.

A company has a custom object, Order__c, that has a custom picklist field, Status__c, with values of `˜New', `˜In Progress', or `˜Fulfilled' and a lookup field, Contact__c, to Contact.
Which SOQL query will return a unique list of all the Contact records that have no `˜Fulfilled' Orders?

A. SELECT Id FROM Contact WHERE Id NOT IN (SELECT Id FROM Order__c WHERE Status__c = 'Fulfilled')

B. SELECT Contact__c FROM Order__c WHERE Status__c <> 'Fulfilled'

C. SELECT Id FROM Contact WHERE Id NOT IN (SELECT Contact__c FROM Order__c WHERE Status__c = 'Fulfilled'

D. SELECT Contact__c FROM Order__c WHERE Id NOT IN (SELECT Id FROM Order__c Where Status__c = 'Fulfilled')

C.   SELECT Id FROM Contact WHERE Id NOT IN (SELECT Contact__c FROM Order__c WHERE Status__c = 'Fulfilled'

Explanation:

To find Contacts who do not have any 'Fulfilled' Orders, we need a query that:
1. Starts from the Contact object, since we want a list of unique Contacts.
2. Excludes Contacts who are associated with any Order__c record where Status__c = 'Fulfilled'.
3. Properly handles the subquery structure and relationship fields.

Let’s evaluate each option carefully:

✅ Correct Answer: C.
SELECT Id FROM Contact WHERE Id NOT IN (SELECT Contact__c FROM Order__c WHERE Status__c = 'Fulfilled')

✅ Explanation:
The outer query fetches all Contact IDs.
The subquery gets the list of Contact__c values from Order__c where Status__c = 'Fulfilled'.
The NOT IN ensures that any Contact who has at least one Fulfilled Order is excluded.
The result is a unique list of Contacts who are not involved in any Fulfilled Orders.
This query follows the correct syntax, correctly references the child-to-parent lookup (Contact__c), and applies the filtering on the child object (Order__c), which is the only proper way to identify this condition.

🔗 Reference: Salesforce Docs – Using Subqueries in SOQL

❌ A. SELECT Id FROM Contact WHERE Id NOT IN (SELECT Id FROM Order__c WHERE Status__c = 'Fulfilled')
The subquery returns Order__c IDs, not Contact IDs.
The outer query compares Contact.Id to Order__c.Id — this is invalid and will throw an error or return incorrect results.
Mismatch of ID types in subquery and outer query.

❌ B. SELECT Contact__c FROM Order__c WHERE Status__c <> 'Fulfilled'
This returns Order records, not Contact records.
Also, it doesn't guarantee uniqueness, and doesn’t filter out Contacts who have both Fulfilled and non-Fulfilled orders.
A Contact with both types of Orders would still appear here, which violates the requirement.

❌ D. SELECT Contact__c FROM Order__c WHERE Id NOT IN (SELECT Id FROM Order__c Where Status__c = 'Fulfilled')
This is querying Order__c, not Contact, and filtering based on Order IDs.
It only returns Order records that are not Fulfilled, but does not ensure the Contact doesn't have other Fulfilled Orders.
Also, the result will be Order__c, not a unique list of Contacts.

✅ Final Answer:
C. SELECT Id FROM Contact WHERE Id NOT IN (SELECT Contact__c FROM Order__c WHERE Status__c = 'Fulfilled')
This is the only correct SOQL query that:
Targets the Contact object.
Filters out Contacts who have any Fulfilled Orders.
Returns a unique list of Contact records.

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.

A Visualforce page needs to make a callout to get billing information and tax information from two different REST endpoints. The information needs to be displayed to the user at the same time and the return value of the billing information contains the input for the tax information callout. Each endpoint might take up to two minutes to process. How should a developer implement the callouts?

A. An HTTP REST callout for the billing callout and a Continuation for the tax callout

B. A Continuation for both the billing callout and the tax callout

C. An HTTP REST callout for both the billing callout and the tax callout

D. A Continuation for the billing callout and an HTTP REST callout for the tax callout

B.   A Continuation for both the billing callout and the tax callout

Explanation:

To determine the best approach, let’s break down the scenario:

➞ A Visualforce page needs to make two REST callouts.
➞ The tax information callout depends on the result of the billing callout (chained callouts).
➞ Each callout may take up to two minutes — which exceeds Apex's standard 10-second limit for synchronous callouts.
➞ The user must see both results at the same time.

In such cases, standard HTTP callouts won't work due to timeouts. You need a way to manage long-running processes—this is exactly what Continuations are built for in Visualforce.

✅ Correct Answer: B. A Continuation for both the billing callout and the tax callout
The Continuation class allows Apex to perform asynchronous callouts that don’t block server threads and support timeouts up to 120 seconds per callout. Since both billing and tax endpoints may take up to 2 minutes, standard synchronous callouts will fail, and using Continuation ensures the Visualforce page remains responsive.

Here, even though the tax callout depends on billing’s result, you can structure the logic such that:
1. The first Continuation callout fetches billing data.
2. Once billing data is available, a second Continuation callout is made using the required input.
3. The final response is returned once both callouts complete.

This can be achieved using chained Continuation callouts, where the second call is triggered within the callback method of the first.
🔗 Reference: Salesforce Developer Guide – Asynchronous Callouts Using Continuations

❌ A. An HTTP REST callout for the billing callout and a Continuation for the tax callout
This option fails because billing is the first call, and if it takes longer than 10 seconds, a synchronous HTTP callout will time out. So this won't work even before reaching the second call.

❌ C. An HTTP REST callout for both the billing callout and the tax callout
This is completely invalid. Standard synchronous Apex callouts only support up to 10 seconds, and both endpoints can take up to 2 minutes. The callouts will timeout and fail.

❌ D. A Continuation for the billing callout and an HTTP REST callout for the tax callout
Even though the billing callout is made using Continuation, the second call (tax) is still synchronous and may timeout due to the long processing time. This hybrid strategy is not reliable for long-running endpoints.

✅ Final Verdict:
B. A Continuation for both the billing callout and the tax callout is the correct and most efficient approach. It adheres to the governor limits, handles long-running callouts gracefully, and fits the dependency pattern between the two REST endpoints.

After a platform event is defined in a Salesforce org,events can be published via which mechanism?

A. External Apps use an API Co publish event messages.

B. Internal Apps can use entitlement processes.

C. External Apps require the standard Streaming API.

D. Internal Apps can use outbound messages.

A.   External Apps use an API Co publish event messages.

Explanation:

To determine how platform events can be published in a Salesforce org after they are defined, let's evaluate the provided options:

➝ A. External Apps use an API to publish event messages.
➝ B. Internal Apps can use entitlement processes.
➝ C. External Apps require the standard Streaming API.
➝ D. Internal Apps can use outbound messages.

Platform events in Salesforce are part of an event-driven architecture, allowing communication of changes or updates within Salesforce or with external systems. Once defined, these events need to be published so that subscribers (internal or external) can receive them. Let's analyze each option to identify the correct mechanism.

Option A: External Apps use an API to publish event messages
External applications, which operate outside of Salesforce, can interact with the platform through APIs. Salesforce provides the REST API and SOAP API, both of which support publishing platform events. For example, an external app can make a REST API call to create an event message, effectively publishing it to the Salesforce org. This is a well-documented and valid mechanism for external systems to publish platform events. Thus, this option appears correct.

Option B: Internal Apps can use entitlement processes
Internal apps refer to functionalities or applications within Salesforce. Entitlement processes, however, are a feature of Salesforce Service Cloud used to manage customer service entitlements, such as support timelines or service contracts. They are not designed for publishing platform events, which is a separate process involving event creation and distribution. This option does not align with the mechanisms available for publishing events, making it incorrect.

Option C: External Apps require the standard Streaming API
The Streaming API in Salesforce is designed for subscribing to real-time notifications, such as PushTopics or generic streaming events. For platform events specifically, subscribers use the CometD protocol to listen for events. However, publishing events is a distinct action that involves creating and sending event messages, not subscribing to them. The Streaming API is not used for publishing events; instead, publishing is handled through APIs (like REST or SOAP) or Apex. Therefore, this option is incorrect.

Option D: Internal Apps can use outbound messages
Outbound messages are a workflow action in Salesforce that send SOAP-based notifications to external systems when specific conditions are met, such as a field update. While they facilitate communication from Salesforce to external services, they are not a mechanism for publishing platform events within the Salesforce ecosystem. Platform events are published using tools like Apex, Process Builder, Flow Builder, or APIs, not outbound messages. This option is also incorrect.

Additional Context and Verification

For completeness, platform events can be published in several ways:
➜ Within Salesforce (internal): Using Apex (e.g., EventBus.publish), Process Builder, or Flow Builder.
➜ Externally: Using the REST API or SOAP API.

The question asks for a mechanism by which events "can be published," and among the options, only A correctly identifies a valid method: external apps using an API. While internal mechanisms like Apex or Flow Builder are also valid, they are not represented in the options. Options B, C, and D describe mechanisms that do not apply to publishing platform events.

Conclusion
The correct mechanism among the given choices is that external apps can use an API to publish event messages. Therefore, the answer is:
A. External Apps use an API to publish event messages.

Salesforce-Platform-Developer-II Exam Questions - Home
Page 2 out of 41 Pages