12 The issue described is rooted in the Salesforce Order of Execution. When a record is saved, Salesforce follows a very specific sequence of events. First, original triggers (before and after) are executed. Only after these triggers have completed does the system evaluate and execute workflow rules.34 In this scenario, th5e following happens:6 * The user saves the Opportunity with the count set to 4.7 * The After Trigger fires. At this point, the field value i8s still 4. Since the trigger logic only creates a child record when the value "changes from 4 to 5," and it is currently exactly 4 (not yet 5), the condition is not met. * Next, the Workflow Rule fires and performs a field update, changing the count from 4 to 5. * According to the platform rules, a workflow field update causes Before and After Triggers to fire one more time to account for the change. However, in this second execution of the after trigger, Trigger.old now contains the value 4 (from the start of the second execution) and Trigger.new contains 5. While the condition old == 4 and new == 5 is now technically true, many developers fail to realize that the first execution (before the workflow) already bypassed the logic because the workflow hadn't updated the value yet. If the trigger was written to look for the exact transition, it might fail during the first pass (where the value is 4) and potentially execute during the second pass. However, if the logic is not specifically handled to account for the re-entrant nature of workflow field updates, or if the "After triggers fire before workflow rules" (Option A) is the primary constraint being tested, it explains why the initial save logic didn't see the "5" until it was too late in the initial trigger context.
PDII-JPN Exam Question 2
Visualforce 検索ページで使用される RemoteAction を定義する以下の Apex クラスを検討してください。 Java global with sharing class MyRemoter { public String accountName { get; set; } public static Account account { get; set; } public MyRemoter() {} @RemoteAction global static Account getAccount(String accountName) { account = [SELECT Id, Name, NumberOfEmployees FROM Account WHERE Name = :accountName]; return account; } } リモート アクションが正しいアカウントを返したことをアサートするコード スニペットはどれですか。
Correct Answer: D
In Salesforce Apex, a @RemoteAction method must be defined as static. Static methods belong to the class itself rather than to a specific instance of the class. Therefore, when writing a unit test to verify the behavior of a RemoteAction, the method should be called using the class name notation (ClassName.methodName) rather than by instantiating the class first. Option D correctly demonstrates the standard way to invoke a static method in Apex: Account a = MyRemoter.getAccount('TestAccount');. Because the method is static, it does not require the new keyword or a constructor to be called. Option A is incorrect because it attempts to call a static method on an instance variable (remote.getAccount), which is considered an illegal or improper reference in Apex. Option B is incorrect because it treats the RemoteAction like an instance method and assumes a non-existent constructor that takes a String. Option C is incorrect because it uses an undefined variable controller. By calling the method statically in the test, the developer correctly simulates how the Visualforce Remoting engine calls the method from JavaScript at runtime. The assertion System.assertEquals then verifies that the record retrieved from the database matches the expected name, ensuring the search logic is functioning correctly.
3233 When a requirement specifies a "non-linear" or highl34y customized layout, the high-35level lightning-record- form (A) is unsuitable because it automatically renders fields in a standard grid or based on a page layout. To achieve a custom UI-such as overlaying fields on a product image-the developer needs more granular control. The lightning-record-edit-form (B) is the ideal container for this scenario. It provides the heavy lifting for data communication (loading and saving records) without imposing a strict visual structure. Within this form, the developer uses lightning-input-field (C) components for each Case field. These components are "context- aware," meaning they automatically inherit metadata like field labels, picklist values, and validation rules directly from the Salesforce object definition. Because lightning-input-field components can be placed anywhere inside the lightning-record-edit-form tag, the developer can use custom CSS (absolute positioning or CSS Grid) to place them precisely over the product image as requested. Standard lightning-input (D) components could work but would require much more manual code to handle data binding, type conversion, and validation, making the combination of B and C the most efficient and platform-aligned approach.
For high-volume, automated standard email communications, Email Alerts with Flow Builder (Option B) is the most scalable and maintainable solution. Salesforce imposes strict limits on the number of "Single" emails sent via Apex (typically 5,000 per 24 hours). However, emails 5sent via Workflow Rules, Process Builder, or Flow6 Builder (Email Alerts) have a much higher daily limit (2,000,000 per org). To meet the requirement of 10,000 emails per day, an Apex-based solution using SingleEmailMessage() (Option D) would likely hit the daily limit and cause transaction failures. MassEmailMessage() (Option C) is generally intended for manual mass mailing to Contacts or Leads and is not optimized for automated, per- record trigger logic. While Batch Apex (Option A) could process many records, the underlying SingleEmailMessage limit would still apply. By using an Email Alert triggered by a Record-Triggered Flow, the developer leverages the platform's high- volume email engine. This approach is declarative, requires no custom code, is easier for administrators to maintain, and comfortably handles the 10,000 daily email requirement without risking governor limit exceptions. It also ensures the "criteria evaluation" happens within the standard Flow entry conditions.
This requirement involves two specific databas26e events: record insertion (for setting defaults) and record deletion (for enforcing business rules/errors). Both Apex Triggers (Option A) and Flow Builder (Option C) are capable of handling these scenarios. Flow Builder is the declarative (low-code) solution. A Record-Triggered Flow can be set to run "Before Save" to efficiently update the Contact's fields with metadata defaults upon insertion. Furthermore, Flow Builder now supports "Before Delete" triggers and the "Custom Error" element, allowing an administrator to block a deletion and present a specific error message to the user if the Contact belongs to a flagged region. Apex Triggers are the programmatic solution. A developer can write a before insert trigger to perform the Custom Metadata lookup and assign field values, and a before delete trigger to evaluate the region and call addError() on the record. Option B (Remote Action) is for Visualforce-to-Apex communication, and Option D (Invocable Method) is a piece of code called by a Flow or Process, not an entry point itself. Therefore, Triggers and Flows are the two primary automation frameworks for these requirements.