Salesforce PDII Online Practice
Questions and Exam Preparation
PDII Exam Details
Exam Code
:PDII
Exam Name
:Salesforce Certified Platform Developer II (Plat-Dev-301)
Certification
:Salesforce Certifications
Vendor
:Salesforce
Total Questions
:445 Q&As
Last Updated
:Jun 19, 2026
Salesforce PDII Online Questions &
Answers
Question 301:
Part of a custom Lightning Component displays the total number of Opportunities in the org, which is in the millions. The Lightning Component uses an Apex Controller to get the data it needs.
What is the optimal way for a developer to get the total number of Opportunities for the Lightning Component?
A. SUM() SOQL aggregate query on the Opportunity object B. SOQL for loop that counts the number of Opportunities records C. COUNT() SOQL aggregate query on the Opportunity object D. Apex Batch job that counts the number of Opportunity records
C. COUNT() SOQL aggregate query on the Opportunity object
Explanation
When you need to retrieve the total count of records in a large dataset (millions of records), a SOQL aggregate query using COUNT() (Option C) is the most efficient and performant method. Salesforce optimizes aggregate functions at the database level. Unlike a standard query that returns individual records and counts against the "50,000 SOQL rows" limit, a COUNT() query returns a single integer result and counts as only one row toward the governor limits.
This allows a developer to count millions of records in a single synchronous transaction without hitting row limits or causing significant CPU time issues. Option B (SOQL for loop) is the worst approach, as it would attempt to load every individual record into memory, hitting the 50,000-row limit almost immediately and likely causing a LimitException or Request Timeout.
Option D (Batch Apex) is unnecessary for a simple count and is much slower because it runs asynchronously. Option A (SUM) is used for adding up values in numeric fields, not for counting the number of records. For high-volume record counting, SELECT COUNT(Id) FROM Opportunity is the platform-standard approach to provide data to a Lightning component efficiently.
Question 302:
A developer is building a Lightning web component that searches for Contacts and must communicate the search results to other Lightning web components when the search completes.
What should the developer do to implement the communication?
A. Publish an event on an event channel. B. Fire an application event. C. Publish a message on a message channel. D. Fire a custom component event.
C. Publish a message on a message channel.
Question 303:
A developer has a test class that creates test data before making a mock call-out, but now receives a `You have uncommitted work pending. Please commit or rollback before calling out' error.
What step should be taken to resolve the error?
A. Ensure both the insertion and mock callout occur after the Test.stopTest(). B. Ensure the records are inserted before the Test.startTest() statement and the mock callout occurs within a method annotated with StestSetup. C. Ensure both the insertion and mock callout occur after the Test.startTest(). D. Ensure the records are inserted before the Test.startTest() statement and the mock callout after the Test.startTest().
D. Ensure the records are inserted before the Test.startTest() statement and the mock callout after the Test.startTest().
Explanation
This error occurs because Salesforce prohibits making a callout (even a mock one) in the same transaction after a DML operation has been performed. When you insert test data, it creates a "pending" transaction in the database. If you then attempt to execute a callout immediately, the platform throws the CalloutException to prevent data inconsistency issues.
To resolve this in a test context, you must separate the DML operation from the callout using the Test. startTest() and Test.stopTest() methods. When Test.startTest() is called, Salesforce provides a fresh set of governor limits and effectively creates a new transaction context for the code that follows. By inserting the records before Test.startTest() and performing the logic that triggers the callout after Test.startTest(), the developer ensures that the DML operation is "committed" to the test database context before the callout is initiated.
Option D correctly identifies this pattern. Option B is incorrect because @testSetup is used for global data creation across all test methods and does not specifically address the callout transaction split. Options A and C do not solve the problem because they either keep the DML and callout in the same context or place the DML in a context where it would still interfere with the subsequent callout request.
Question 304:
Given the following code:
Java
for ( Contact c : [SELECT Id, LastName FROM Contact WHERE CreatedDate = TODAY] )
{ Account a = [SELECT Id, Name FROM Account WHERE CreatedDate = TODAY LIMIT 5];
A. AccountId = a.Id;update c;}Assuming there were 10 Contacts and five Accounts created today, what is the expected result? B. System. QueryException: List has more than one row after Assignment on Account. C. System. LimitException: To many SOQL Queries on Account. D. System. QueryException: To many DML Statement errors on Contact E. System. LimitException: Too many SOQL Queries on Contract
A. AccountId = a.Id;update c;}Assuming there were 10 Contacts and five Accounts created today, what is the expected result?
Explanation
The primary issue in this code snippet is a violation of basic variable assignment rules in Apex when dealing with SOQL results. In the line Account a = [SELECT Id, Name FROM Account ... ], the code attempts to assign the result of a query directly to a single SObject variable (Account a).
In Apex, a SOQL query assigned to a single SObject variable must return exactly one record . If the query returns zero records, it throws a System.QueryException: List has no rows for assignment. If the query returns more than one record , it throws a System.QueryException: List has more than one row for assignment (Option A). Since the prompt explicitly states that five Accounts were created today and the query is not filtered to a single unique ID, the query will return five records. Even though there is a LIMIT 5 clause, that only caps the results at five; it does not ensure only one is returned. To fix this, the result should be assigned to a List<Account> or the query should be filtered to return exactly one row.
While the code also violates the "SOQL in a loop" best practice, it would not hit the LimitException (Option B) in this specific case because the loop only runs 10 times (10 contacts), and the limit is 100 queries. The runtime assignment error occurs before any governor limits are breached.
Question 305:
How should a developer assert that a trigger with an asynchronous process has successfully run?
A. Create at test data in the test class, use System.runAs() to invoke the trigger, then perform assertions. B. Insert records into Salesforce, use seeAllData-true, then perform assertions. C. Create all test data, use @future In the test class, then perform assertions. D. Create all test data in the test class, invoke Test.startTest() and Test.stopTest() and then perform assertions.
D. Create all test data in the test class, invoke Test.startTest() and Test.stopTest() and then perform assertions.
Question 306:
What is the transaction limit for the number of records for SOSL?
A. 20 B. 2,000 C. 100 (synchronous), 200 (async) D. 200 (synchronous), 100 (async) E. There is no limit
B. 2,000
Question 307:
Universal Containers (UC) has enabled the translation workbench and has translated picklist values. UC has a custom multi-select picklist field, Products__z, on the Account object that allows sales reps to specify which of UC's products an Account already has. A developer is tasked with writing an Apex method that retrieves Account records, Including product_c field.
What should the developer do to ensure the value of Products__c is in the current user's language?
A. Set the locale on each record in the SOQL result list. B. Use the locale clause in the SOQL query. C. Use toLabel1 Products_c in the fields list of the SOQL query. D. Call the translate ( ) method on each record in the SOQL result list.
C. Use toLabel1 Products_c in the fields list of the SOQL query.
Explanation
When a Salesforce organization uses the Translation Workbench, picklist values can be translated into multiple languages. By default, a SOQL query returns the "Master" or API value of a picklist field, which is usually in English. If a developer needs the returned data to reflect the translated labels based on the current user's language settings, they must use the toLabel() function within the SOQL SELECT statement.
Using SELECT toLabel(Products__c) FROM Account (Option C) tells the Salesforce query engine to look up the translated value for each picklist entry in the result set before returning it to Apex. This is particularly useful for UI components or reports where the user expects to see values in their native tongue. It works for both standard picklists and multi-select picklists.
Other options are incorrect because they do not exist as standard Apex features. There is no translate() method on SObject records (Option D), and Apex does not allow you to manually "set the locale" on individual records to trigger translation (Option A). There is also no "locale clause" in SOQL syntax (Option B). Using toLabel() is the platform-standard, most efficient way to handle localized data retrieval directly within the data access layer.
Question 308:
A developer created the following test method:
@isTest(SeeAllData= true)
public static void testDeleteTrigger(){
Account testAccount = new Account(name = 'Test1');
insert testAccount;
List<Account> testAccounts = [SELECT Id, Name from Account WHERE Name like 'Test%'];
System.assert(testAccounts.size() > 0);
delete testAccounts;
testAccounts = [SELECT Id, Name from Account WHERE Name like 'Test%'];
System.assert(testAccounts.size() == 0);
}
The developer org has five accounts where the name starts with Test". The developer executes this test in the Developer Console. After the test code runs, which statement is true?
A. The test will fail. B. There will be no accounts where the name starts with "Test". C. There will be five accounts where the name starts with Test". D. There will be six accounts where the name starts with Test".
C. There will be five accounts where the name starts with Test".
Explanation
Every Apex test execution is treated as a temporary transaction. One of the most critical aspects of this execution is that any changes made to the database--including the insertion, modification, or deletion of records--are automatically rolled back at the end of the test run. This mechanism ensures that unit tests do not leave behind "garbage" data or alter the state of the organization's actual business data, maintaining a consistent environment for development and production.
In this specific scenario, the @isTest(SeeAllData=true) annotation is used, which allows the test method to view existing data in the organization. Because the org already contains five accounts starting with "Test," the test method sees them. When the test code inserts a new account named "Test1," the count within that specific transaction becomes six. The subsequent code queries for these six accounts and deletes them. While the test is running, the deletion is successful, which is why the assertion checking for zero accounts passes.
However, once the test finishes, the entire transaction is rolled back. The rollback effectively "undoes" the deletion of the original five accounts and the creation of the one new account. Consequently, the organization returns to its exact state from before the test was initiated. The five original accounts remain in the database as if the test never occurred, making option C the correct answer.
Question 309:
1 Contact con = new Contact( LastName ='Smith', Department = 'Admin') 2 insert con;
3 Contact insertedContact=[select Name from Contact where id=:con.Id];
4 Savepoint sp_admin = Database.setSavepoint();
5 con.Department = 'HR';
6 update con;
7 Database.rollback(sp_admin);
8 System.debug(Limits.getDmlStatements());
Given the following code, what value will be output in the logs by line #8?
A. 5 B. 3 C. 4 D. 2
C. 4
Question 310:
A developer is inserting, updating, and deleting multiple lists of records in a single transaction and wants to ensure that any error prevents all execution.
How should the developer implement error exception handling in their code to handle this?
A. Use Database methods to obtain lists of Database.SaveResults. B. Use Database.setSavepoint() and Database.rollBack() with a Try/Catch statement. C. Use a Try/Catch and use sObject.addError() on any failures. D. Use a Try/Catch statement and handle DML cleanup in the catch statement.
B. Use Database.setSavepoint() and Database.rollBack() with a Try/Catch statement.
Explanation
To ensure "all-or-nothing" behavior across multiple, distinct DML operations (such as an insert followed by a delete), a developer must manage the transaction boundary manually. In Apex, while a single insert statement is atomic, multiple statements are not automatically linked; if the second statement fails, the first statement's changes would typically remain committed to the database.
The correct implementation is to use Savepoints (Option B) . By calling Database.setSavepoint(), the developer marks a specific state of the database. All subsequent DML operations are wrapped in a try-catch block. If an exception occurs during any of the operations, the code enters the catch block, where Database. rollback(sp) is called. This command reverts the database to the exact state it was in when the savepoint was created, effectively undoing any successful DML that occurred before the error.
Option A (SaveResults) allows for partial success, which contradicts the requirement to "prevent all execution." Option D (manual cleanup) is error-prone and cannot reliably revert system-generated fields or complex triggers. Option C (addError) is used in triggers to block a transaction but does not provide the programmatic rollback control needed for general Apex logic involving multiple lists.
Nowadays, the certification exams become more and more important and required by more and more
enterprises when applying for a job. But how to prepare for the exam effectively? How to prepare
for the exam in a short time with less efforts? How to get a ideal result and how to find the
most reliable resources? Here on Vcedump.com, you will find all the answers.
Vcedump.com provide not only Salesforce exam questions,
answers and explanations but also complete assistance on your exam preparation and certification
application. If you are confused on your PDII exam preparations
and Salesforce certification application, do not hesitate to visit our
Vcedump.com to find your solutions here.