+ Start a Discussion

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.

Hi Jim,

You can use condition in the test method.

You can take a look at this post

Abhi Tripathi
Salesforce Certified Developer