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
@rajeshdulhai@rajeshdulhai 

How to give action to custom button to go on new visualforce page

i have 2 visualforce pages . one is for displaying records and another for creating records . On displaying records pages i have a button named creating new record . onclick of this button i want to redirect this page to creating records page

please help me in code for apex controller

thanks in advance

 

 

 

 

 

hitesh90hitesh90

Hi,

 

You have to use PageReference function to redirect page to another page.

Below is the sample example to redirect page to another page on click of command button.

 

Visualforce Page:

<apex:page controller="ctrlCustomcontroller" >
	<apex:form>
		<apex:commandButton value="Go to New Page" action="{!createNewRecord}"/>
	</apex:form> 
</apex:page> 

 

Apex Class:

public class ctrlCustomcontroller{
	public pageReference createNewRecord(){ 
		pageReference pr = new pageReference('/apex/yourpagename');
		pr.setRedirect(true);
		return pr; 
	}
}

 

 

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.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/