function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Varun99Varun99 

Pagereference in vf page

Hello All,

 

        How to redirect to record edit page from visual force page and when i click cancel button in edit record(redirect to object record)it return back to visual force page my page had pagination.

 

For example am in 5th page one record edit it will redirect object record edit when i click on cancel

it will back to same 5th page. How to redirect?

 

 

Can any one explain?

 

Thanks 

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Hi varun,

 

here is the example to redirect page to account edit page.

public PageReference EditPage() {  
	string accid= ApexPages.currentPage().getParameters().get('id');
	PageReference acctPage = new PageReference('/'+accid+'/e?retURL='+yourcurrentpageName);
	acctPage.setRedirect(true);
	return acctPage;
}

 For redirect to Navigation page

public PageReference CancelPage() {
    string strYourpagename = ApexPages.currentPage().getParameters().get('retURL');
	PageReference acctPage = new PageReference('/apex/'+strYourpagename);
	acctPage.setRedirect(true);
}

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thanks,
Hitesh Patel
SFDC Certified Developer & Administrator

All Answers

hitesh90hitesh90

Hi varun,

 

here is the example to redirect page to account edit page.

public PageReference EditPage() {  
	string accid= ApexPages.currentPage().getParameters().get('id');
	PageReference acctPage = new PageReference('/'+accid+'/e?retURL='+yourcurrentpageName);
	acctPage.setRedirect(true);
	return acctPage;
}

 For redirect to Navigation page

public PageReference CancelPage() {
    string strYourpagename = ApexPages.currentPage().getParameters().get('retURL');
	PageReference acctPage = new PageReference('/apex/'+strYourpagename);
	acctPage.setRedirect(true);
}

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thanks,
Hitesh Patel
SFDC Certified Developer & Administrator

This was selected as the best answer
Bhawani SharmaBhawani Sharma
public PageReference edit() {
PageReference pRef = ApexPages.StandardController(account).edit();
pReg.getParameters.put('retURL', ApexPages.currentPage().getURL());
return pRef;
}

You don't need to write cancel method explicitly. If you have retURL, standard controller's cancel method will take care of that.
You just need:
<apex:commandButton action="{!Cancel}" value="Cancel" />
Varun99Varun99

Hi all,

 

Thanks for your quick reply. It will help to my requirement.

 

 

 

Thank you.