次のコードがあるとします。 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; } 今日、連絡先が 10 件、アカウントが 5 件作成されたと仮定すると、どのような結果が期待されますか?
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.
To build a maintainable and scalable solution, a developer must separate business logic from trigger execution and avoid hard-coding threshold values. First, the $1,000,000 threshold should be stored in Custom Metadata (Option B). Custom Metadata is superior to hard-coding or even Custom Settings in this context because the records are deployable and can be queried efficiently without counting against standard SOQL limits. If the business decides to lower the "high value" threshold to $500,000, an administrator can simply update the Custom Metadata record without requiring any code changes or redeployments. Second, the logic to identify these opportunities should be moved to a Helper Class (Option D). This follows the "Separation of Concerns" principle. Instead of writing the SOQL query and logic inside the trigger, the trigger calls a method in the helper class. Similarly, the Lightning Web Component's Apex controller can call the exact same method in the helper class. This ensures that the definition of a "high value opportunity" is managed in one single place in the codebase. If the logic becomes more complex (e.g., adding Industry filters), the developer only needs to update the helper class once to satisfy both the trigger and the UI component. Option A leads to "spaghetti code," and Option C is impossible as triggers cannot be called directly from JavaScript or other Apex classes.
PDII-JPN Exam Question 28
開発者は、様々なデバイスでレスポンシブな Lightning Web コンポーネントを作成するという課題を抱えています。この目標を達成するために役立つ 2 つのコンポーネントはどれですか。
Correct Answer: B,D
To build a responsive user interface in Lightning Web Components (LWC), developers rely on the layout system provided by the Lightning Design System (SLDS). This system is primarily implemented through two tightly coupled components: lightning-layout and lightning-layout-item. lightning-layout acts as a flexible container (a flexbox wrapper). It allows developers to arrange child components in a row or column and manage horizontal and vertical alignment. It provides the overall structure for the grid. lightning-layout-item is the child component that resides within a lightning-layout. It is responsible for defining the actual proportions of the content across different breakpoints (small, medium, and large devices) using attributes like size, small-device-size, medium-device-size, and large-device-size. Together, these two components allow a developer to specify exactly how much space a piece of content should occupy depending on the user's screen size. For example, a sidebar might occupy 100% of the width on a phone but only 25% on a desktop. lightning-input-location is a specific input field for geolocation data, and lightning-navigation is a service used for page routing; neither is involved in the visual responsiveness or structural layout of the component. Therefore, options B and D are the essential building blocks for responsive design.
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.
In Large Data Volume (LDV) environments, Salesforce uses the Query Optimizer to determine if a query can use an index. A query is "selective" if it filters the records using an indexed field and reduces the result set to less than 10% of the first million records. * Option A is highly selective. The Id field is the primary key and is always indexed. Filtering by a list of IDs is the most efficient way to query records because it allows the database to perform a direct index lookup. * Option B is selective because it filters on the Name field (which is a standard indexed field) and Customer_Number__c. In the context of PDII, a field like "Customer Number" is typically marked as an External ID, which automatically creates a custom index. Even without the second filter, the IN clause on an indexed field like Name makes the query selective. Option C is non-selective because negative filters (using !=) and "not null" checks generally force the database to perform a full table scan. Option D is non-selective because it uses a leading wildcard (% Partner). While the Name field is indexed, the index cannot be used if the search string starts with a wildcard, as the database must inspect the end of every string in the table.