A developer created a Lightning web component that allows users to input a text value that is used to search for Accounts by calling an Apex method. The Apex method returns a list of AccountWrappers and is called imperatively from a JavaScript event handler. Java 01: public class AccountSearcher { 02: 03: public static List<AccountWrapper> search(String term) { 04: List<AccountWrapper> wrappers = getMatchingAccountWrappers(term); 05: return wrappers; 06: } 07: 08: 09: public class AccountWrapper { 10: public Account account { get; set; } 11: public Decimal matchProbability { get; set; } 12: } 13: // ...other methods, including getMatchingAccountWrappers implementation... 14: } Which two changes should the developer make so the Apex method functions correctly?
Correct Answer: C,D
For an Apex method to be reachable by a Lightning Web Component, it must be annotated with @AuraEnabled. In this code, line 03 is the entry point for the search functionality. Without the @AuraEnabled annotation on line 03 (Option D), the JavaScript controller will not be able to "see" or invoke the search method, resulting in a runtime error. Furthermore, because this method returns a custom "Wrapper" class, the platform's serialization engine needs to know which specific properties within that wrapper class should be sent to the client-side JavaScript. By default, the LWC framework does not serialize class members unless they are explicitly marked. Therefore, the developer must add @AuraEnabled to lines 10 and 11 (Option C). Without this, even if the method executes successfully, the account and matchProbability properties will be stripped during the JSON conversion, and the component will receive a list of empty objects. Adding @AuraEnabled to the class definitions themselves (Lines 01 or 09) is not required; the annotation is only necessary on the specific methods and member variables that participate in the data exchange between Apex and JavaScript. This explicit marking ensures security and efficiency by only exposing the data intended for the user interface.
PDII Exam Question 17
Universal Containers implements a private sharing model for Convention_Attendee__c. A lookup field Event_Reviewer__c was created. Management wants the event reviewer to automatically gain Read/Write access to every record they are assigned to. What is the best approach?
Correct Answer: A
In a private sharing model, access is restricted to the owner and those above them in the hierarchy. When a specific user is identified in a lookup field (like Event_Reviewer__c), standard sharing rules cannot dynamically grant access to that specific individual because sharing rules only target Roles, Public Groups, or Territories.1 The solution is Apex Managed Sharing (Option A). By using an after insert (and likely after update) trigger, the developer can pro2grammatically create records in the object's "Share" table (e.g., Convention_Attendee__Share). Each share record specifies the UserOrGroupId (from the lookup field), the AccessLevel ('Edit' for Read/Write), and a RowCause (Apex Sharing Reason). The "After" trigger is required because the ID of the Convention_Attendee__c record must exist before a Share record can be associated with it. "Before" triggers (Option B) are used for field updates on the record itself, not for creating related sharing records. Options C and D are not viable because they cannot dynamically reference a User ID stored within a field on the record itself. Apex Managed Sharing provides the most granular and automated way to handle this dynamic security requirement.
PDII Exam Question 18
Universal Containers (UC) has enabled the translation workbench and has translated picklist values. UC has a custom multi-select picklist field, Products__c, 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 the Products__c field. What should the developer do to ensure the value of Products__c is in the current user's language?40
Correct Answer: A
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 A) 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 B), and Apex does not allow you to manually "set the locale" on individual records to trigger translation (Option C). There is also no "locale clause" in SOQL syntax (Option D). Using toLabel() is the platform-standard, most efficient way to handle localized data retrieval directly within the data access layer.
PDII Exam Question 19
A developer created a Lightning web component that uses a lightning-record-edit-form to collect information about Leads. Users complain that they only see one error message at a time about their input when trying to save a Lead record. Which best practice should the developer use to perform the validations on more than one field, thus allowing more than one error message to be displayed simultaneously?
Correct Answer: B
When using lightning-record-edit-form, server-side validation rules (Option D) typically return errors one at a time as the database engine encounters them, or as a single combined toast message that can be difficult to parse. To provide a superi1or user experience where multiple fields are validated simultaneously before the data even reaches the server, the develo2per shou3ld implement Client-side validation (Option B). In the component's JavaScript controller, the developer can intercept the onsubmit event. By iterating through all the lightning-input-field or standard lightning-input elements, the developer can programmatically check for various conditions (e.g., custom regex patterns, conditional logic between fields, or range checks). Each field can then be marked with a custom error message using the reportValidity() or setCustomValidity() methods. This allows the UI to highlight all invalid fields at once, providing immediate, comprehensive feedback to the user. This approach reduces unnecessary server round-trips and ensures that the user can correct all issues in a single pass before successfully submitting the record.
PDII Exam Question 20
Which method should be used to convert a Date to a String in the current user's locale?
Correct Answer: D
Handling date and time formatting across different countries is a common requirement in global Salesforce orgs. For example, a user in the US expects MM/DD/YYYY, while a user in the UK expects DD/MM/YYYY. The Date.format() method (Option D) is specifically designed to handle this localization automatically. When called on a Date instance, it converts the value into a String based on the locale settings of the logged- in user. This is the most efficient and localized approach as it requires no manual mapping of date patterns. Option A (Date.parse) is the inverse; it converts a localized String into a Date object. Option C (String. valueOf) returns a standard, non-localized format (YYYY-MM-DD), which is used for system logging or API payloads but is often confusing for end-users. Option B (String.format) is used for variable substitution within a string (e.g., "Hello {0}") and does not inherently handle date localization. By using the native .format() method, developers ensure a consistent and familiar user experience for employees worldwide.