1

My use case was--> referenced a void method in the action attribute on an apex:page In the void method, check for a condition. if true, do nothing, else call a pagereference method to redirect to another page.

I tried using a void method here since the general opinion seems to be that using a pagereference method and returning null is bad programming.

But this didnt work, the page never redirected when expected. The same logic with a pagereference returning null works fine.

2

IN your specific case where it could return a pagereference or not based on a condition, using a pagereference as a return type is the proper way to do it.

The only time having a signature that returns a pagereference is "bad programming" is when it ALWAYS returns null;

  • Thank you for your response and verifying this. Although I'm still wondering if they DONT allow pagereference method calls from within void methods. Will assume they don't (from what I experienced through my attempt), regardless, marking as accepted. – arlon Aug 14 '15 at 18:35
  • 1
    If the return type of the initial method is void, you cannot return a pagereference. Even if your method calls another method that does return a pagereference. The other method would be returning that the the original method and the original method would still return void to the page.... – Eric Aug 14 '15 at 20:27

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.