0

We are trying to build a Rest Service layer above existing code base.

In many scenarios the constructor is populating the class variables through getting the current page url parameters. But when we are trying to call those controller from our service class we are not able to set the current page reference so that the controller can pick up parameter (i.e. url?param1=abc&param2=xyz) values for given page reference.

Is there any way to achieve the similar scenario where we set currentPageReference in test classes, but it is not possible to use above method as it is a non-test scenario.

Any help would be much appreciated.

1

Consider using method overloads to define these methods in such a way that they don't depend on the current PageReference. For example:

public void doStuff()
{
    Map<String, String> params = ApexPages.currentPage().getParameters();
    doStuff(params.get('param1'), params.get('param2'));
}
public void doStuff(String param1, String param2)
{
    // logic here
}

If you can completely break the dependency on your controller state and make this method static, that would make it easier to reuse as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.