function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JimDeLongJimDeLong 

Is it possible: in testMethod - dynamically generate controller for page ref?

In a testMethod, can I dynamically instantiate a page's controller?

I have a page, p1, which has a controller c1, and I write the testMethod to give me a page ref off of p1, and the controller from c1 to c2 - could the testMethod have been written to figure that out?

I could envision a solution where if I were sometimes using c1 and sometimes using c2, so I could have if statements determine which to instantiate.

But I would need to know this up front if I were going to use this approach in a managed package. If the user of the system were to add c3 after I built the package - then I wouldn't be able to accomodate it.

Abhi_TripathiAbhi_Tripathi
Hi Jim,

You can use condition in the test method.

You can take a look at this post
http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

Regards,
Abhi Tripathi
Salesforce Certified Developer