A company has reference data stored in multiple custom metadata records that represent default information and delete behavior for certain geographic regions. When a contact is inserted, the default information should be set on the contact. Additionally, if a user attempts to delete a contact that belongs to a flagged region, the user must get an error message. Depending on company personnel resources, what are two ways to automate this?16
Correct Answer: B,D
Comprehensi22ve and Detailed 150 to 250 words of Explanation: This requirement involves two different automation triggers: record creation (insert) and record deletion (delete). To handle these events, Salesforce provides both declarative and programmatic options. Flow Builder (Option B) is the preferred declarative tool. Record-Triggered Flows can be configured to run "Before" a record is saved to handle the default value assignment upon insertion. They can also be configured to run when a record is deleted. Using the "Custom Error" element within a Flow, an administrator can easily block a deletion and present a user-friendly error message if the contact belongs to a flagged region. Apex Triggers (Option D) are the programmatic equivalent. A developer can write a before insert trigger to perform the metadata lookup and set field defaults, and a before delete trigger to check the region and call addError() on the record to prevent the deletion. Options A (Remote Action) and C (Invocable Method) are not standalone automation triggers. A Remote Action is for JavaScript-to-Apex communication in Visualforce, and an Invocable Method is a piece of code called by another tool like a Flow or Strategy Builder. Therefore, Flow and Triggers are the two primary mechanisms to satisfy both the insertion and deletion requirements.
PDII Exam Question 72
Part of a custom Lightning component displays the total number of Opportunities in the org, which are in the millions. The Lightning component uses an Apex method 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?
Correct Answer: A
When you need to retrieve the total count of records in a large dataset (millions of records), a SOQL aggregate query using COUNT() (Option A) is the most efficient and performant method. Salesforce optimizes aggregate functions at the database 13level. Unlike a standard query that returns in14dividual records and counts against the "50,000 SOQL rows" limit, a COUNT() query returns a single integ15er result and counts as only one row to16ward the governor limits.17 This allows a developer to count millions of records in a single synchronous transactio18n without hitting row limits or causing significant CPU time issues. Option D (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 B (Batch Apex) is unnecessary for a simple count and is much slower because it runs asynchronously. Option C (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.
PDII Exam Question 73
What are three reasons that a developer should write Jest tests for Lightning web components?
Correct Answer: A,D,E
Jest is a powerful JavaScript testing framework used for Lightning Web Components (LWC) to ensure individual units of code function correctly in isolation. One of the primary reasons to use Jest is to verify the DOM output of a component (D). Since LWC is a UI framework, Jest allows developers to inspect the rendered HTML to ensure that elements, classes, and data are displayed as intended after a state change. Furthermore, Jest is essential for testing basic user interaction (A). Developers can simulate events like button clicks or text input and then assert that the component's state or UI updates accordingly. Another critical use case is to verify that events fire when expected (E). Components often communicate with parents via custom events; Jest allows you to "spy" on these events to ensure they are dispatched with the correct detail payload at the right time. Conversely, Jest is not intended for testing how multiple components work together (C)-this is the domain of integration tests or end-to-end tests (like UTAM). Additionally, Jest tests should focus on the component's public API and observable behavior; testing non-public (private) properties (B) is generally discouraged as it leads to brittle tests that break upon internal refactoring. By focusing on DOM output, interactions, and events, Jest provides a fast, reliable way to maintain component quality.
PDII Exam Question 74
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]; c.AccountId = a.Id; update c; } Assuming there were 10 Contacts and five Accounts created today, what is the expected result?
Correct Answer: A
2 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 3to 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 C) 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.