You need to sign in to do that
Don't have an account?
suresh dupada
What is the use of PageReference ?..........
For Example
public Pagereference method1()
{
return null;
}
why we use pagereference as a return type,............ what is the situation to use the pagereference,,,,......... Please explain me with code example..............
public Pagereference method1()
{
return null;
}
why we use pagereference as a return type,............ what is the situation to use the pagereference,,,,......... Please explain me with code example..............
There are several standard parameters like setRedirect which can be used for hard "reset" of controller state. If you make it false then state of variables in controller is maitained across many VF pages.
If you want to add any custom parameters then you can add them like below
So, overall code will look like
Quick Answers to your questions:
1. Why we use pagereference as a return type?
- We normally set return type to a PAgeReference when we need user to other VF page. We return "null" if we want user on same page and we normally return "null" in catch blocks.
2. What is the situation to use the pagereference?
- When you want to jump to other VF page when something is clicked and method takes you to new VF page or refreshing current page by doing "return null;"
3. Please explain me with code example
- Explained above!
PS: if this answers your question then hit Like and mark it as solution!
All Answers
PageReference is object in the salesforce, It is use to navigate the user to a different page or Url as the result of an action method.
Example :
public PageReference returnPage() {
// Send the user to the detail page for the new account.
PageReference acctPage = new ApexPages.StandardController(account).view();
acctPage.setRedirect(true);
return acctPage;
}
There are several standard parameters like setRedirect which can be used for hard "reset" of controller state. If you make it false then state of variables in controller is maitained across many VF pages.
If you want to add any custom parameters then you can add them like below
So, overall code will look like
Quick Answers to your questions:
1. Why we use pagereference as a return type?
- We normally set return type to a PAgeReference when we need user to other VF page. We return "null" if we want user on same page and we normally return "null" in catch blocks.
2. What is the situation to use the pagereference?
- When you want to jump to other VF page when something is clicked and method takes you to new VF page or refreshing current page by doing "return null;"
3. Please explain me with code example
- Explained above!
PS: if this answers your question then hit Like and mark it as solution!
My code below is not working.
public PageReference cancel()
{
PageReference pgref = new PageReference('/home/home.jsp');
pgref.setRedirect(true);
return pgref;
}
when clicking cancel button it has to go to homepage in lightning.Instead I'm getting error.Kindly help