Monday, August 4, 2014

What is PageReference class in Salesforce?

What is PageReference class in Salesforce?

A PageReference is a reference to an instantiation of a page. Among other attributes, PageReferences consist of a URL and a set of query parameter names and values.

Use a PageReference object:
· To view or set query string parameters and values for a page
·  To navigate the user to a different page as the result of an action method

PageReference methods are all called by and operate on a particular instance of a PageReference 

The table below describes the instance methods for PageReference.

Controller :

public class PageReferenceController {
Account account;
    public Account getAccount() {
        if(account == null) account = new Account();
        return account;

    public PageReference save() {
        // Add the account to the database. 
        insert account;
        // Send the user to the detail page for the new account.
        PageReference acctPage = new ApexPages.StandardController(account).view();
        return acctPage;

In controller class once the account record details is entered and click on save button the PageReference will redirect you to Newly created Account record detail page using the 

 PageReference acctPage = new ApexPages.StandardController(account).view();

Visualforce Page:

<apex:page controller="PageReferenceController" tabStyle="Account">
    <apex:sectionHeader title="New Account Edit Page" />
    <apex:form >
        <apex:pageBlock title="Create a New Account">
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!save}" value="Save"/>
            <apex:pageBlockSection title="Account Information">
                <apex:inputField id="accountName" value="{!}"/>
                <apex:inputField id="accountSite" value="{!}"/>


save image

 once you click on save button it will save the record and display in record detail page.

save image

That's it ..
Thanks for Reading...


Post a Comment

| ,