The issue described involves hitting DML limits due to a high volume of records (over 10,000) being processed in a single transaction. In Salesforce, a single synchronous transaction or a standard Scheduled Apex job has strict governor limits on the number of DML statements (150) and the total number of records processed (10,000 for DML rows). To resolve this, the developer should implement the Database.Batchable interface. Batch Apex is specifically designed to handle large data volumes by breaking the processing into smaller, manageable chunks (batches) of records (default 200). Each batch runs within its own transaction context, resetting the governor limits for that specific batch. This prevents the "Too many DML rows" exception. While Queueable (Option D) and @future (Option C) provide asynchronous processing, they are not inherently designed to iterate over large datasets in the same robust, governor-limit-safe manner as Batch Apex, particularly when the record count exceeds the thousands.
To make a Lightning Web Component (LWC) available for use in the Lightning App Builder, the developer must modify the component's configuration file (the .js-meta.xml file). First, the isExposed tag must be set to true. By default, this is false, meaning the component is only available to other components within the namespace but not to the App Builder or Experience Builder. Setting it to true exposes it to the tools. Second, the developer must specify where the component can be dragged and dropped by defining targets. Since the question states the component displays information about the "record in context," it implies the component is designed to live on a Record Page. Therefore, adding <target>lightning__RecordPage</target> is essential. While lightning__AppPage (Option D) is a valid target, the context of "record in context" strongly points to the Record Page target. There is no IsVisible attribute in the LWC configuration schema.
1516 In Salesforce Apex, each DML statement is its own mini-transaction unless specific measures are taken to group them. If a developer performs an insert parent; followed by an insert child;, and the child insertion fails due to a validation rule, the parent record remains in the database. This leads to "orphaned" parent records, violating the bu17siness requireme18nt that every parent must have a child. To ensure "all-or-nothing" behavior across multiple DML statements, the developer should use Database. setSavepoint() and Database.rollback(). By setting a savepoint before the parent is inserted, the developer creates a "marker" for the database state. If the child insertion fails and throws an exception, the code enters the catch block. Within the catch block, the developer can call Database.rollback(sp), which reverts the database to the state before the parent was ever inserted. This ensures that either both records are created successfully or neither is created. Option A is incorrect because allOrNone only applies to the records within a single Database.insert() call; it cannot link the success of two separate DML calls for different objects. Option B is a manual cleanup approach that is less reliable than a system-level rollback. Option D is typically used in triggers to prevent saving, but it doesn't provide the transactional control needed in a custom method with multiple DML steps. Using savepoints is the standard best practice for managing multi-object transaction atomicity.
PDII-JPN Exam Question 64
テストクラスで Visualforce ページを初期化するためのベストプラクティスは何ですか?
Correct Answer: C
When writing unit tests for Visualforce controllers, the code must be executed within a simulated "Page Context." Without setting this context, methods that rely on ApexPages.currentPage() (such as retrieving URL parameters or adding page messages) will fail with a null pointer exception. The standard and correct syntax to set this context is Test.setCurrentPage(Page.MyTestPage); (Option C). The Page reference (e.g., Page.MyTestPage) is a special system variable that represents the URL of the Visualforce page. Passing this into Test.setCurrentPage() tells the Apex testing engine: "Act as if the browser is currently looking at this specific page." Options A and B use incorrect syntax that does not exist in the Apex language. Option D is a secondary step; you use .getParameters().put() after setting the current page to simulate passing specific values (like an ID) in the URL. By properly initializing the page context using Option C, the developer ensures that the controller's logic-including constructors and action methods-can be tested accurately and reliably.
Comprehensive and Deta10iled 150 to 250 words of E11xplanation: This error occurs because Salesforce prohibits making a callout (even a mock one) in the same transaction after a DML operation has been performed. When you insert test data, it creates a "pending" transaction in the database. If you then attempt to execute a callout immediately, the platform throws the CalloutException to prevent data inconsistency issues. To resolve this in a test context, you must separate the DML operation from the callout using the Test. startTest() and Test.stopTest() methods. When Test.startTest() is called, Salesforce provides a fresh set of governor limits and effectively creates a new transaction context for the code that follows. By inserting the records before Test.startTest() and performing the logic that triggers the callout after Test.startTest(), the developer ensures that the DML operation is "committed" to the test database context before the callout is initiated. Option C correctly identifies this pattern. Option B is incorrect because @testSetup is used for global data creation across all test methods and does not specifically address the callout transaction split. Options A and D do not solve the problem because they either keep the DML and callout in the same context or place the DML in a context where it would still interfere with the subsequent callout request.