When processing large data volumes in Apex, the "Heap Size" limit (6MB for synchronous, 12MB for asynchronous) is a common bottleneck. This limit tracks the amount of memory consumed by objects and variables currently in scope. Option B utilizes the SOQL For Loop pattern. This is the most memory-efficient approach because it processes records in "chunks" of 200 at a time using internal query locators. Instead of loading the entire result set (potentially thousands of records) into a single collection in memory, the SOQL For Loop iterates through the records without ever holding the full set in the heap. This prevents the "Apex heap size too large" error when dealing with high-volume queries. In contrast, Options A, C, and D all involve assigning the entire query result to a collection (a Map or List) before the loop begins. This immediately consumes heap space proportional to the number of records and fields retrieved. If the query returns a large number of records, these collections will quickly exceed the heap limit before the first line of the loop even executes. Therefore, for bulk data processing where memory efficiency is the priority, the inline SOQL For Loop (Option B) is the standard best practice.
PDII-JPN Exam Question 22
次の包含階層があるとします。 HTML <template> <c-my-child-components></c-my-child-components> </template> プロパティが my-child-component 内で定義されている場合、「passthrough」という名前のプロパティの新しい値を my-parent-component に伝達する正しい方法は何ですか?
Correct Answer: C
In Lightning Web Components (LWC), data flows "down" via properties and "up" via events. When a child component needs to communicate a change in a property or state to its parent, it must dispatch a CustomEvent. To pass specific data-such as the new value of the passthrough property-along with the event, the developer must use the detail property within the event initialization object. Option C is the correct syntax. It creates a new CustomEvent named 'passthrough' and assigns the current value of the component's property (this.passthrough) to the detail key. The parent component can then listen for this event (using onpassthrough={handleEvent}) and access the value via event.detail. Option A is incorrect because it wraps the variable in quotes, passing the literal string "this.passthrough" instead of the actual data. Option B creates an event but fails to include the data payload, meaning the parent would know an event occurred but wouldn't receive the new value. Option D uses incorrect syntax for event naming and variable referencing. Using the standard CustomEvent constructor with the detail property is the platform- standard way to ensure robust, typed data communication between component layers in the Shadow DOM.
PDII-JPN Exam Question 23
開発者が Lightning Web コンポーネントの Jest テストを記述する必要がある 3 つの理由は何ですか?
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.
In Salesforce, a critical restriction is that synchronous callouts cannot be made from within an Apex trigger. This architectural limitation is in place because triggers execute as part of a database transaction. Allowing a synchronous callout-which waits for a response from an external system-would keep the database connection and transaction locks open for an indeterminate amount of time. This could lead to severe performance bottlenecks and row-locking issues across the entire organization. Therefore, if a developer needs to initiate an external integration based on a record change (trigger), the logic must be handed off to an asynchronous process, such as a @future(callout=true) method, a Queueable class, or a Platform Event. Regarding the other options: A callout that takes longer than the maximum timeout (120 seconds) will fail regardless of whether it is synchronous or asynchronous, though async is often preferred for longer-running tasks to avoid blocking the user UI. Salesforce allows up to 100 callouts in a single transaction, so making more than 10 (Option C) does not inherently force an asynchronous approach unless the 100-callout limit is exceeded. Finally, the use of the REST API (Option D) is simply a protocol choice and does not dictate the execution context. Consequently, the presence of an Apex trigger is the only scenario listed that programmatically mandates the use of asynchronous execution to perform a callout.
Comprehensive and Detailed Explanation: Salesforce enforces test isolation, meaning unit tests do not have access to the data in the organization by default. However, some objects are considered "metadata-like" or "setup objects" and are always visible to tests without special annotations. These include Users (Option C), Profiles (Option D), and RecordTypes (Option A). Conversely, some objects are considered "data" but cannot be easily created within a test method due to their complexity or nature. Reports (Option B), along with Pricebooks and Folders, fall into a category where access to existing org data is often required because the platform does not support DML operations to create them in a test context. To query for an existing Report record in a unit test, the test class or method must be annotated with @isTest(seeAllData=true). Note: It is a best practice to avoid seeAllData=true whenever possible to ensure tests are deterministic and independent of the environment, but it remains a requirement for Report-related logic.