I'm not totally sure what your question is so forgive me if it's stuff you already know, but you return a PageReference when you want to redirect or forward to a different page. You return null if you want to stay on the same page, usually because you're doing some type of partial page update.
You can also make your action methods void so you don't have to return null.
Ok, so in many of the examples SFDC put in their training, or examples you see on the net do something like this:
List<String> lStr = New List<String>();
public PageReference doSomething(){
// random stuff
lStr.add('String1');
lStr.add('String2');
//end random stuff
return null;
}
Why do this versus just making the method void.......Why use that as an example.....One would be led to believe there is something purpose to it when it is used in many SFDC examples.
Sorry Saurabh but your answer has nothing to do with the question as to why use pagereference as the return value when all you will ever return is null. Good reference on returning a pagereference though
Both PageReference and void work so the example is still valid.
My guess is that using PageReference makes it explicit that we're referring to an action method.
All Answers
I'm not totally sure what your question is so forgive me if it's stuff you already know, but you return a PageReference when you want to redirect or forward to a different page. You return null if you want to stay on the same page, usually because you're doing some type of partial page update.
You can also make your action methods void so you don't have to return null.
Ok, so in many of the examples SFDC put in their training, or examples you see on the net do something like this:
List<String> lStr = New List<String>();
public PageReference doSomething(){
// random stuff
lStr.add('String1');
lStr.add('String2');
//end random stuff
return null;
}
Why do this versus just making the method void.......Why use that as an example.....One would be led to believe there is something purpose to it when it is used in many SFDC examples.
Both PageReference and void work so the example is still valid.
My guess is that using PageReference makes it explicit that we're referring to an action method.
Thanks, that is what I figured but I want to make sure there was not some hidden meaning that needed to be decoded :)