Testing asynchronous Apex (such as @future methods, Batchable, or Queueable classes) requires a specific mechanism to ensure that background tasks complete before the test verifies the results. In a standard execution, asynchronous jobs are queued and run whenever system resources are available, which means a test's assertion statements might execute before the background job has even started. To address this, Salesforce provides the Test.startTest() and Test.stopTest() methods.78 When t9he code that initiates an asynchronous process is placed between Test.startTest() and Test.stopTest(), the platform behaves di10fferently. All asynchronous calls made within this block are collected and held by the system. As soon as the 11code reaches Test.stopTest(), the test execution pauses, and the system forces all queued asynchronous jobs to ru12n immediately and synchronously within the same thread. Once Test. stopTest() finishes, the execution continues to the next line. By placing assertions immediately after Test. stopTest(), the developer is guaranteed that the asynchronous logic has finished its work. This is the only supported way to reliably test the side effects of background processes. Other options, like using System. runAs() or seeAllData=true, do not affect the timing of asynchronous execution and will likely result in failed assertions.
Comprehensive and 19Detailed 150 to 250 words of Explanation:20 This integration requiremen21t involves two specific needs: sending a custom JSON payload and handling a response that involves updating data in Salesforce. Outbound Messaging (Option C) is a declarative tool, but it is limited to XML/SOAP protocols and cannot send JSON. Therefore, a custom programmatic solution using Apex is required to construct and send the JSON payload to the external REST service. Since the integration must be triggered by an event in Salesforce (likely the upload or update of a product record), an Apex trigger is the most direct starting point. However, as noted in previous questions, callouts cannot be performed directly within a trigger's execution context because they would block the database transaction. The developer must use asynchronous processing to handle the callout. An @future(callout=true) method is the standard way to achieve this. The trigger captures the necessary data, passes it to the future method, and the future method then performs the HTTP request to the external application. Once the external application resizes the image, it can use the Salesforce REST API to send the resized file back to Salesforce. While Platform Events (Option D) are a modern alternative for event-driven architectures, they would still require an asynchronous subscriber (like a trigger or a flow) to actually perform the callout, making the Trigger + Future method combination the most straightforward and traditional answer for this PDII scenario.
PDII-JPN Exam Question 13
Lightning Web コンポーネントがロードされたときにカスタムロジックを実行できる手法はどれですか?
Correct Answer: B
In Lightning Web Components (LWC), the component lifecycle is managed by standard Web Component lifecycle hooks. To run logic exactly once when the component is inserted into the Document Object Model (DOM), a developer should use the connectedCallback() method (Option B). The connectedCallback() is the LWC equivalent of Aura's init event. It is the ideal place to: * Perform initial data fetching (via imperative Apex). * Initialize internal state or variables. * Subscribe to a Lightning Message Service (LMS) channel. * Establish communication with the parent component. Option A and D are Aura-specific syntax and are not valid in LWC. Option C (renderedCallback()) runs every time the component finishes a render cycle. Because a component can re-render many times (whenever a reactive property changes), placing initialization logic in renderedCallback can lead to performance issues or infinite loops if not guarded carefully. Therefore, connectedCallback() is the standard, most efficient way to handle "on load" logic in LWC.
The lightning-record-form is a powerful, high-level component that simplifies data entry and display. However, its performance is heavily influenced by the layout-type attribute. When layout-type="Full" is used, the component fetches and renders every single field defined on the object's "Full" page layout in the Salesforce metadata. In this case, the Account object has 275 fields. Fetching and rendering such a large volume of metadata and data causes a significant performance lag, even if the user only cares about three specific fields. To improve performance, the developer should switch from a layout-based approach to a field-based approach. By removing the layout-type attribute and adding the fields attribute (Option A), the developer can pass an array of only the specific field API names required (e.g., ['Name', 'CustomField1__c', 'CustomField2__c']). This drastically reduces the amount of data requested from the Lightning Data Service (LDS) and minimizes the DOM elements the browser needs to render. Option C is incorrect because "Partial" is not a valid value for layout-type; the only supported values are "Full" and "Compact". Option B only affects the visual spacing of the fields and does not reduce the data load. Option A is the direct and most effective way to optimize component responsiveness by limiting the data scope.
When a trigger unexpectedly executes twice (recursion), it is typically due to the Salesforce Order of Execution. A common cause is a workflow rule, process, or flow updating the same record that initiated the transaction, which re-triggers the original Apex trigger. To identify exactly where this second execution is being initiated, the most effective technique is to use system.debug() statements in conjunction with the Developer Console logs (Option D). By placing debug statements at the start of the trigger (e.g., System.debug('Trigger Fired');), the developer can examine the execution log to see how many times that line appears. More importantly, the execution log provides a hierarchical "trace" of the entire transaction. The developer can look for entries like FLOW_CREATE_INTERVIEW or WF_RULE_EVAL_BEGIN between the two trigger execution blocks. This trace reveals exactly which automation (Flow, Workflow, or another Trigger) caused the record to be updated a second time. Option A is inefficient and disruptive to production environments. Option B is too broad and doesn't provide the internal execution context. Option C checks for code validity but does not diagnose runtime logic issues in a live environment. Tracing the execution through logs is the standard programmatic way to debug recursion and side effects in Salesforce.