Tag Archives: Apex

Redirecting Back to Previous Page Using Visualforce Page StandardController

Visualforce Page Button:

<apex:commandButton action="{!back}" value="Back"/>

Apex Controller:

public with sharing class ExampleController
{
    private ApexPages.StandardController sctrl;
    public SaveAndReturnController(ApexPages.StandardController stdController)
    {
        this.sctrl = stdController;
    }
 
    public PageReference back()
    {
        PageReference cancel = sctrl.cancel();
        return cancel;
    }
}

Add Fields in ApexPages.StandardController

If you want any fields value then you need add the field API name in standard controller.

public with sharing class AccountControllerExt
{
	public Account acc {get;set;}
	 
	public AccountControllerExt(ApexPages.StandardController stdController)
	{
		stdController.addFields(new List<String>{'Name', 'Region__c', 'TAX_ID_Number__c'});
		this.acc = (Account)stdController.getRecord();
	}
}