PDII Practice Test Questions

193 Questions


A dev created a class that implements the Queueable Interface as follows:
public class without sharing OrderQueueableJob implements Queueable{
public void execute(QueueableContext context){
// logic
System.enqueueJob(New OrderQueueableJob));
}
}
As part of the deployment process, the dev is asked to create a corresponding test class. Which two actions should the dev take to successfully execute the test class?


A. Implement seeAllData=True to ensure the Queueable job is able to run in bulk mode.


B. Ensure the running user of the test class has, at least, View All permissions on the Order object.


C. Enclose System.enqueuJob(new OrderQueueableJob) within Test.startTest() and Test.stopTest()


D. Implement Test. isRunningTest() to prevent chaining jobs during test execution.





B.
  Ensure the running user of the test class has, at least, View All permissions on the Order object.

C.
  Enclose System.enqueuJob(new OrderQueueableJob) within Test.startTest() and Test.stopTest()

Explanation:

For an Apex method to be called imperatively from an LWC, it must be declared as public or global, static, and annotated with @AuraEnabled. In this example, the Apex method that returns a list of AccountWrapper objects is defined on line 03. Therefore, the method should be annotated with @AuraEnabled so it can be invoked from your Lightning web component.

Additionally, when you return custom objects (like your AccountWrapper), all properties that need to be accessible on the client side must also be annotated with @AuraEnabled. In the provided code snippet, the properties on lines 11 and 12 require this annotation. This ensures that the framework can serialize and send the data to the client-side LWC.

By adding @AuraEnabled to the Apex method and its properties, you enable the method to be called imperatively and have its returned data properly processed in your Lightning web component.

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.

Explanation:

Test.startTest() and Test.stopTest() are used to ensure that any asynchronous processes (like @future methods, batch Apex, or queueable jobs) have been executed and completed within a test method. These methods simulate a fresh execution context and allow the developer to assert that the asynchronous process was executed successfully.

Universal Containers has an Apex trigger on Account that creates an Account Plan record when an Account is marked as a Customer. Recently a record-triggered flow was added so that whenever an Account is marked as a Customer, a ‘Customer Since’ date field is updated with today’s date. Since the addition of the flow, two Account Plan records are created whenever the Account is marked as a Customer. What might cause this to happen?


A. The flow is configured to evaluate when a record is created and every time it is edited.


B. The Apex trigger is not bulk safe and calls insert inside of a for loop.


C. The Apex trigger does not use a static variable to ensure it only fires once.


D. The flow is configured to use an ‘Update Records’ element.





C.
  The Apex trigger does not use a static variable to ensure it only fires once.

Explanation:

In Salesforce, both a trigger and a flow could be updating the same record, causing the trigger to run multiple times. If the Apex trigger doesn't use a static variable to prevent multiple executions in a single transaction, it can result in creating duplicate records. The static variable ensures that the trigger only fires once, even if the record is updated multiple times within the same transaction.

There are user complaints about slow render times of a custom data table within a Visualforce page that loads thousands of Account records at once. What can a developer do to help alleviate such issues?


A. Use the transient keyword in the Apex code when querying the Account records


B. Use JavaScript remoting to query the accounts


C. Use the standard Account List controller and implement pagination


D. Upload a third-party data table library as a static resource





C.
  Use the standard Account List controller and implement pagination

Explanation:

When dealing with large datasets (like thousands of Account records), rendering all records at once on a Visualforce page will lead to slow performance and poor user experience. The best solution is to implement pagination, which limits the number of records loaded and rendered at any one time.


Why C. Use the standard controller with pagination is correct:

The standard list controller provides built-in support for pagination.
You can display a subset of records (e.g., 50 or 100 at a time).
This reduces the memory usage, server processing time, and rendering load on the browser.
Pagination can be extended with custom logic as needed.

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.

Explanation:

When building Lightning Web Components (LWC) that need to communicate across components that aren’t in the same DOM hierarchy, the correct mechanism is the Lightning Message Service (LMS).

Why Lightning Message Service (LMS) is the right choice:

It allows communication between sibling or unrelated components, including across different DOM trees and containers (e.g., standard components, utility bar, etc.).
You define a message channel using a Lightning Message Channel (LMC).
You publish a message (e.g., the search results) in one component, and subscribe to that message in any other component, regardless of hierarchy.

A developer is debugging an Apex-based order creation process that has a requirement to have three savepoints, SP1, SP2, and 5P3 {created in order), before the final execution of the process. During the final execution process, the developer has a routine to roll back to SP1 for a given condition. Once the condition is fixed, the code then calls 2 roll back to SP3 to continue with final execution. However, when the roll back to SP3 is called, a Funtime error occurs. Why does the developer receive a runtime error?


A. SP3 became invalid when SP1 was rolled back.


B. The developer has too many DML statements between the savepoints.


C. The developer used too many savepoints in one trigger session.


D. The developer should have called SF2 before calling SP3.





A.
  SP3 became invalid when SP1 was rolled back.

Explanation:

In Apex, when you perform a rollback to a savepoint, all subsequent savepoints created after that rollback point are discarded. In this scenario, rolling back to SP1 invalidates any savepoints that were created after SP1, including SP3. When the code later attempts to roll back to SP3, a runtime error occurs because SP3 no longer exists in the transaction context. This behavior is inherent to Salesforce’s transaction control mechanism, ensuring that once a rollback happens, only the state of the database at the rollback point is preserved, and all later savepoints are lost.

A developer must perform a complex SOQL query that joins two objects in a Lightning component. How can the Lightning component execute the query?


A. Invoke an Apex class with the method annotated as @AuraEnabled to perform the query


B. Use the Salesforce Streaming API to perform the SOQL query


C. Create a Process Builder to execute the query and invoke from the Lightning component


D. Write the query in a custom Lightning web component wrapper and invoke from the Lightning component





A.
  Invoke an Apex class with the method annotated as @AuraEnabled to perform the query

Explanation:

Lightning Web Components (LWC) and Aura components cannot execute SOQL directly. To perform a complex SOQL query, especially one involving joins between objects (like parent-to-child or child-to-parent queries), you need to use Apex.

Why Apex with @AuraEnabled is correct:

You define an Apex method that performs the SOQL query.
Annotate the method with @AuraEnabled so it can be invoked from a Lightning component.
The component then calls this method imperatively or via wire, depending on the use case.

Universal Containers implements a private sharing model for the Convention_Attendee_ _c 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 Read/Write 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 criteria-based sharing rule on the Convention Attendee custom object to share the records to 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.


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


D. 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.

Explanation:

Universal Containers has:

A private sharing model for Convention_Attendee__c, meaning users do not have access to records they don’t own unless explicitly shared.
A custom lookup field (Event_Reviewer__c), and reviewers must get Read/Write access to the records they’re assigned.

Why Apex Managed Sharing via an After Insert trigger is the best solution:

Private sharing model means access must be explicitly granted.
The Event_Reviewer__c field is a dynamic user, so criteria-based sharing rules won’t work unless you hardcode criteria or share with a group (which doesn’t satisfy individual dynamic access).
Apex Managed Sharing gives fine-grained control to programmatically share records with specific users.
The sharing logic needs to happen after the record exists (i.e., in an After Insert trigger), because sharing rules require a record ID.

Users report that a button on a custom Lightning web component (LWC) is not saving the data they enter. The button looks to be clicked, but the LWC simply sits there, seemingly doing nothing. What should the developer use to ensure error messages are properly displayed?


A. Add a try-catch block surrounding the DML statement.


B. Use the Database method with a110rNone Set to false.


C. Add the tag to the component.


D. Add JavaScript and HTML to display an error message.





D.
  Add JavaScript and HTML to display an error message.

Explanation:

Why This Is the Best Approach?

User Experience (UX) Requirement
If the LWC appears unresponsive, users need visible feedback when errors occur.
Simply wrapping code in try-catch (Option A) or using Database methods (Option B) does not display errors to users.

Implementation Steps

HTML: Add an error message container (e.g., < lightning - messages > or a custom < div >).
JavaScript: Catch errors and update the UI.

Which statement is true regarding savepoints?


A. You can roll back to any savepoint variable created in any order.


B. Static variables are not reverted during a rollback.


C. Reference to savepoints can cross trigger invocations.


D. Savepoints are not limited by DML statement governor limits.





B.
  Static variables are not reverted during a rollback.

Explanation:

When an Apex transaction is rolled back to a previously set savepoint, only the database state is reverted to that savepoint—the changes that have occurred in the database since that point are undone. However, static variables reside in memory and are not part of the database state. As a result, their values are not reverted when the transaction is rolled back. This means any changes made to static variables persist even after a rollback, which can be important to remember when designing transactional logic in Apex.

Let's briefly examine the other options:

A. "You can roll back to any savepoint variable created in any order." This is incorrect because once you roll back to an earlier savepoint, any savepoints created after that point become invalid and cannot be referenced or rolled back to.
C. "Reference to savepoints can cross trigger invocations." While triggers in the same transaction share the transaction context, savepoints are scoped to the transaction in which they’re created; they do not persist beyond that, and their references cannot be reused arbitrarily across different transaction contexts.
D. "Savepoints are not limited by DML statement governor limits." This statement is inaccurate; although Salesforce does impose various governor limits, the concept of savepoints is tied to the transaction control mechanism in Salesforce and is not directly limited by the DML governor limits.

Universal Containers decided to use Salesforce to manage a new hire interview process. A custom object called Candidate was created with organization-wide defaults set to Private. A lookup on the Candidate object sets an employee as an Interviewer.
What should be used to automatically give Read access to the record when the lookup field is set to the Interviewer user?


A. The record can be shared using an Apex class.


B. The record can be shared using a permission set.


C. The record can be shared using a sharing rule.


D. The record cannot he shared with the current setup.





A.
  The record can be shared using an Apex class.

Explanation:

The Candidate object has OWD (Organization-Wide Default) set to Private, which means users only see records they own or that are explicitly shared with them.

In this scenario:

There is a lookup field to a User (Interviewer).
When this field is set, the Interviewer should be given Read access to the Candidate record.
Since the sharing is based on a dynamic field value (Interviewer), and not on a role, group, or criteria that is static, the correct solution is:

Apex Managed Sharing using an Apex class.
This allows:

Programmatically sharing the record with the user in the Interviewer field.
Setting the access level (Read in this case).
Automatically triggering sharing logic when the Interviewer is assigned.

What is the best practice to initialize a Vizualforce page in a test class?


A. Use Test. setCurrentPage (Page. MyTeatPage);


B. Use Test. currantPage .getParamatars put (MyTaestPaga) ;


C. Use controller. currentPage. setPage (MyTastfage) ;


D. Use Test. setCurrentPage MyTestPags;





A.
  Use Test. setCurrentPage (Page. MyTeatPage);

Explanation:

In a Visualforce test class, the best practice for initializing a page is to use the Test.setCurrentPage() method, passing in a reference to the Visualforce page (i.e., Page.MyTestPage). This sets the current page context for the test, allowing controller code (even custom controllers or controller extensions) to properly reference page attributes, parameters, and state. This approach is standard and ensures that any page-level logic in your Visualforce page is properly simulated during test execution.


Page 3 out of 17 Pages
Previous