I've got a class which acts as a controller extension. The class is designed to add a number of fields to the StandardController so a component used on the page can dynamically access some fields.
However, when I went to test the class, I encountered the error:
System.SObjectException: You cannot call addFields when the data is being passed into the controller by the caller.
I tried using reset()
:
System.SObjectException: You cannot call reset when the data is being passed into the controller by the caller.
As far as I can tell, the data is fully initialized before it is passed along to the next object. I'm at a bit of a loss on how to cover these lines. The code below is an example that exhibits the same behavior, right now, the code I am using I just skip the line using Test.isRunningTest
, but I'd like a solution to provide total coverage.
Extension Class
public class TestController_extension {
public TestController_extension(ApexPages.StandardController standardController) {
standardController.addFields(new List<String>{});
}
}
Test Class
@isTest
private class TestController_extension_test {
@isTest
private static void test() {
Account a = new Account();
ApexPages.StandardController controller = new ApexPages.StandardController(a);
TestController_extension extension = new TestController_extension(controller);
}
}