Free Salesforce PDI Exam Actual Questions

The questions for PDI were last updated On Nov 19, 2024

Question No. 1

A developer needs to make a custom Lightning Web Component available in the Salesforce Classic user interface. Which approach can be used to accomplish this?

Show Answer Hide Answer
Correct Answer: D

To make a Lightning Web Component (LWC) available in Salesforce Classic, you can embed it in a Visualforce page using Lightning Out.

Option D: Use the Lightning Out JavaScript library to embed the Lightning Web Component in a Visualforce page and add to the page layout.

Lightning Out allows LWCs to be embedded in Visualforce pages.

The Visualforce page can then be included in Salesforce Classic interfaces.

Why Not Other Options:

Option A: Visualforce components cannot directly contain LWCs.

Option B: Wrapping an LWC in an Aura component and surfacing it as a Visualforce tab doesn't make it available on page layouts.

Option C: You cannot invoke an LWC from a Visualforce page using an Apex method call.


Lightning Out for Visualforce:

'Lightning Out is a feature that extends Lightning components to any web page. Use it to embed Lightning web components in a Visualforce page.' --- Lightning Web Components Dev Guide: Use Lightning Web Components in Visualforce Pages

Question No. 2

A developer has a Visualforce page and custom controller to save Account records. The developer wants to display any validation rule violations to the user.

How can the developer make sure that validation rule violations are displayed?

Show Answer Hide Answer
Correct Answer: A

When saving records using a custom controller in a Visualforce page, validation rule violations can occur. To display these validation error messages to the user, the developer should use the component.

Option A: Include on the Visualforce page.

Correct Approach.

The component displays all messages that were generated for all components on the page, including validation rule violations.

When a DML operation is performed, any validation errors are automatically added to the ApexPages message collection.

Including in the page ensures that these messages are displayed to the user.

Example:

<!-- Form fields for Account -->

While a try/catch block can catch exceptions, it is not required for displaying validation errors.

Validation rule violations are added to the message collection automatically.

Using try/catch may suppress the standard error handling.

Option C: Add custom controller attributes to display the message.

Inefficient Approach.

Manually adding controller attributes and logic to handle error messages adds unnecessary complexity.

The standard component handles this automatically.

Option D: Perform the DML using the Database.upsert() method.

Not Sufficient Alone.

Using Database.upsert() allows for finer control over DML operations and error handling.

However, unless the errors are added to the message collection, they will not be displayed.

The developer would still need to handle displaying the errors.

Conclusion:

By including the component on the Visualforce page, validation rule violations and other error messages are displayed to the user automatically.

Therefore, Option A is the correct answer.


apex

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messages.htm

Displaying Errors

Option B: Use a try/catch with a custom exception class.

Not Necessary.

Question No. 3

A developer wrote Apex code that calls out to an external system using REST API.

How should a developer write the test to prove the code is working as intended?

Show Answer Hide Answer
Correct Answer: D

When writing tests for Apex code that performs callouts to external services, Salesforce requires that callouts are mocked to ensure that tests do not depend on external systems and to allow for consistent and predictable test results.

Correct Option:

Option D: Write a class that implements HttpCalloutMock.

True.

To test HTTP callouts, you implement the HttpCalloutMock interface and provide a fake response for the HTTP request.

This mock response is then used in your test methods to simulate the callout.

The test method uses Test.setMock to set the mock class.

WebServiceMock is used for testing SOAP callouts, not REST (HTTP) callouts.

Since the code uses REST API, HttpCalloutMock is appropriate.

HttpCalloutMock is an interface, not a class. You cannot extend an interface; you implement it.

The correct approach is to implement the HttpCalloutMock interface.


Testing HTTP Callouts by Implementing HttpCalloutMock

Incorrect Options:

Option A & C: Write a class that implements or extends WebServiceMock.

False.

Testing SOAP Callouts

Option B: Write a class that extends HttpCalloutMock.

False.

Interface vs. Class

Conclusion:

To properly test REST API callouts in Apex, you should write a class that implements HttpCalloutMock and use it in your test methods.

Question No. 4

What is the value of the Trigger.old context variable in a before insert trigger?

Show Answer Hide Answer
Correct Answer: C

In a before insert trigger:

Trigger.old is null.

There is no existing record in the database to reference.

Why Not Other Options:

Option A: Describes Trigger.new.

Option B: The variable is defined but has a null value.

Option D: Trigger.old is not an empty list; it is null.


Trigger Context Variables:

'In insert triggers, Trigger.old is null because the records are new.' --- Apex Developer Guide: Trigger Context Variables

Question No. 5

A developer created a trigger on the Account object. While testing the trigger, the developer sees the error message 'Maximum trigger depth exceeded'.

What could be the possible causes?

Show Answer Hide Answer
Correct Answer: C

The error message 'Maximum trigger depth exceeded' occurs when a trigger invokes itself recursively more than the allowed limit.

Option C: The trigger is getting executed multiple times.

Correct Answer.

This error indicates that the trigger is recursively calling itself.

This can happen if the trigger performs an update or insert operation that causes the same trigger to fire again, leading to an infinite loop.

Salesforce enforces a limit on the recursion depth to prevent stack overflows.

User permissions do not cause the 'Maximum trigger depth exceeded' error.

Option B: The trigger is too long and should be refactored into a helper class.

*Incorrect, but possible code improvement.

While refactoring code into helper classes is a good practice, it does not directly address the recursion issue causing the error.

Option D: The trigger does not have sufficient code coverage.

Incorrect.

Code coverage issues affect deployment but do not cause runtime errors like 'Maximum trigger depth exceeded'.

Conclusion:

The error is caused because the trigger is getting executed multiple times due to recursion, leading to exceeding the maximum trigger depth.


Triggers and Order of Execution

Preventing Recursive Triggers

Incorrect Options:

Option A: The developer does not have the correct user permission.

Incorrect.