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; } } リモート アクションが正しいアカウントを返したことをアサートするコード スニペットはどれですか。
正解: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.