Salesforce Platform Developer II Exam Practice Test

Page: 1 / 14
Total 202 questions
Question 1

A developer wrote an Apex class to make several callouts to an external system.

If the URLs used in these callouts will change often, which feature should the developer use to minimize changes needed to the Apex class?



Answer : C

The correct feature to use is C, Named Credentials. Named Credentials are a secure way of storing the endpoint and authentication details for callouts to external services. When URLs change frequently, using Named Credentials allows you to manage the endpoint URL in one place without changing the Apex code.


Named Credentials

Question 2

A developer needs to add code to a Lightning web component's configuration file so the component only renders for a desktop size form factor when on a record page.

What should the developer add to the component's record page target configuration to meet this requirement?

A)

B)

C)

D)



Answer : B

When you want a Lightning web component to only render for a specific form factor, you can use the <targets> tag within the component's .xml configuration file. To specify that the component should only appear on a desktop, you use the <targetConfig> tag with the targets='lightning__RecordPage' attribute and nest a <supportedFormFactors> tag inside it. Within this tag, you include a <supportedFormFactor> tag with the attribute type='Large'.

Option B is the correct markup to ensure that the component only appears for the desktop form factor on a record page.


Lightning Web Components Developer Guide - Configure Components for Lightning Experience and the Salesforce Mobile App

Question 3

Given the following containment hierarchy:

What is the correct way to communicate the new value of a property named ''passthrough'' to my-parent-component if the property is defined within my-child-component?

A)

B)

C)



Answer : A

To communicate a property change up a containment hierarchy in Lightning Web Components (LWC), the child component should dispatch a custom event with the detail of the change. The parent component listens for this event and handles it accordingly.

Option A is the correct method because it creates a new custom event with the detail property containing the new value of passthrough. This event is then dispatched, and the parent component can listen for this event to handle the updated value.

Options B, C, and D are incorrect because they either don't pass any data with the event or they don't use the detail object which is the standard way to pass data with custom events in LWC.


Lightning Web Components Developer Guide - Communicating with Events

Question 4

As part of a custom interface, a developer team creates various new Lightning web components. Each of the components handles errors using toast messages. When the development is complete, all the components are added to the same Lightning page.

During acceptance testing, users complain about the long chain of toast messages that display when errors occur loading the components.

Which two techniques should the developer implement to improve the user experience?

Choose 2 answers



Answer : A, D

The scenario describes a common issue when multiple components are used on the same Lightning page and each component manages its error handling independently, leading to a 'long chain of toast messages' which can be overwhelming for users.

To improve user experience, the developers can implement the following techniques:

A . Use a Lightning web component to aggregate and display all errors: This method involves creating a centralized component responsible for handling all error messages. This component would receive error notifications from other components and then display them in a user-friendly manner. The benefit of this approach is that it provides a single, consistent interface for error messages, reducing the clutter and confusion that can be caused by multiple toasts.

D . Use public properties on each component to display the error messages: By using public properties, components can expose their error states to a parent or orchestrating component, which can then display these errors in a single, consolidated way. This avoids the issue of multiple toast notifications and allows for a more integrated error handling experience.

The other options presented are less ideal:

B . Using the window.alert() method is not recommended in a professional Salesforce environment as it is considered a disruptive way to show errors and does not align with the Salesforce Lightning design system.

C . Using a <template> tag to display in-place error messages could be a viable option for displaying error messages within the component itself, but it does not address the issue of multiple errors stacking up from different components as described in the scenario.


For building a centralized error handling component: Lightning Web Components Developer Guide - Error Handling

For implementing public properties: Lightning Web Components Developer Guide - Public Properties

Question 5

A developer needs to implement a system audit feature that allows users, assigned to a custom profile named "Auditors", to perform searches against the historical records in the Account object. The developer must ensure the search is able to return history records that are between 6 and 12 months old.

Given the code below, which select statement should be inserted below as a valid way to retrieve the Account History records ranging from 6 to 12 months old?

A)

B)

C)

D)



Answer : B

Given the code snippet, the correct query to retrieve Account History records between 6 and 12 months old would be the one that includes a WHERE clause filtering records where the CreatedDate is greater than or equal to initialDate and less than or equal to endDate. Option B's statement does this correctly by using the >= and <= operators to define the range between initialDate (which is set to today's date minus 12 months) and endDate (set to today's date minus 6 months). Options A, C, and D either use incorrect comparison operators or compare against the wrong variables, resulting in an incorrect data set being returned.

Reference

SOQL Date Formats and Date Literals: SOQL and SOSL Reference Guide


Question 6

Which two best practices should the developer implement to optimize this code? Choose 2 answers



Answer : C, D

To optimize the code in question, it's important to follow best practices that reduce the number of SOQL queries and DML statements within loops, as these can quickly consume governor limits and lead to inefficiencies. Option C is correct because using a collection to hold records and performing a single DML operation outside of loops reduces the number of DML operations, which is a best practice for bulkifying code in Salesforce. Option D is also correct because querying records outside of a loop prevents hitting SOQL governor limits and makes the code more efficient. Options A and B are not correct in the context provided, as there isn't enough information to determine if changing the trigger context is necessary, and removing the DML statement altogether may not be feasible if the logic requires data to be persisted.

Reference

Apex Best Practices: Apex Developer Guide Best Practices


Question 7

A developer is writing a Visualforce page that queries accounts in the system and presents a data table with the results. The users want to be able to filter the results based on up to five fields. However, the users want to pick the five fields to use as filter fields when they run the page.

Which Apex code feature is required to facilitate this solution?



Answer : D

The requirement described in the question calls for a flexible way to query records based on user-selected fields. Dynamic SOQL is the perfect tool for this job as it allows the construction of a SOQL string at runtime, which can include any number of fields and filter conditions that are determined at the time the user interacts with the page. This enables the creation of a highly customizable query interface. A, B, and C are not suitable for this requirement as they serve different purposes: A (Streaming API) is for receiving real-time streams of data changes, B (Metadata API) is for managing the metadata of your Salesforce org, and C (variable binding) is used in Visualforce to bind data between the page and the controller but does not provide dynamic query capabilities.

Reference

Dynamic SOQL: Dynamic SOQL in Apex Developer Guide


Page:    1 / 14   
Total 202 questions