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
harsha vardhan vasaharsha vardhan vasa 

hi i am doing a simple code in vf page where i gather customer information like name,contact number etc, i want to know how to redirect to some url on click of submit button and save as well.PFB snippet

<apex:page standardcontroller="comingpeople__c"   sidebar="false" showHeader="false">
<apex:form >

<apex:pageBlock >
<apex:pageBlockSection title="OUTING PLAN">
<apex:inputField value="{!comingpeople__c.Employee_name__c}" /><br/>
<apex:inputField value="{!comingpeople__c.GID__c}" /><br/>
<apex:inputField value="{!comingpeople__c.coming_or_not__c}" /><br/>
<apex:inputField value="{!comingpeople__c.Transportation__c}" /><br/>
<apex:inputField value="{!comingpeople__c.Venue__c}" /><br/>
</apex:pageBlockSection>

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

</apex:pageBlock>
</apex:form>
</apex:page>
Best Answer chosen by harsha vardhan vasa
Lokesh KumarLokesh Kumar
Hi Harsha,

Please write an extension like below and try you will be able to redirect to any Page or URL.

VisualForce Page.
<apex:page standardcontroller="comingpeople__c" extension="DoRedirect"  sidebar="false" showHeader="false">
<apex:form >

<apex:pageBlock >
<apex:pageBlockSection title="OUTING PLAN">
<apex:inputField value="{!comingpeople__c.Employee_name__c}" /><br/>
<apex:inputField value="{!comingpeople__c.GID__c}" /><br/>
<apex:inputField value="{!comingpeople__c.coming_or_not__c}" /><br/>
<apex:inputField value="{!comingpeople__c.Transportation__c}" /><br/>
<apex:inputField value="{!comingpeople__c.Venue__c}" /><br/>
</apex:pageBlockSection>

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

</apex:pageBlock>
</apex:form>
</apex:page>

Apex Extension: 
 
public class DoRedirect {
private ApexPages.StandardController controller;
public MyPageController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference save() {
  controller.save(); // This takes care of the details for you.
  PageReference custompage = Page.Yourcustom_Page; // Provide the page name of URL.
  //OR PageReference pageRef = new PageReference('http://www.google.com');
  custompage.setRedirect(true);
  return custompage;
}

let me know if this helps you !!

Thanks
Lokesh

All Answers

Lokesh KumarLokesh Kumar
Hi Harsha,

Please write an extension like below and try you will be able to redirect to any Page or URL.

VisualForce Page.
<apex:page standardcontroller="comingpeople__c" extension="DoRedirect"  sidebar="false" showHeader="false">
<apex:form >

<apex:pageBlock >
<apex:pageBlockSection title="OUTING PLAN">
<apex:inputField value="{!comingpeople__c.Employee_name__c}" /><br/>
<apex:inputField value="{!comingpeople__c.GID__c}" /><br/>
<apex:inputField value="{!comingpeople__c.coming_or_not__c}" /><br/>
<apex:inputField value="{!comingpeople__c.Transportation__c}" /><br/>
<apex:inputField value="{!comingpeople__c.Venue__c}" /><br/>
</apex:pageBlockSection>

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

</apex:pageBlock>
</apex:form>
</apex:page>

Apex Extension: 
 
public class DoRedirect {
private ApexPages.StandardController controller;
public MyPageController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference save() {
  controller.save(); // This takes care of the details for you.
  PageReference custompage = Page.Yourcustom_Page; // Provide the page name of URL.
  //OR PageReference pageRef = new PageReference('http://www.google.com');
  custompage.setRedirect(true);
  return custompage;
}

let me know if this helps you !!

Thanks
Lokesh
This was selected as the best answer
harsha vardhan vasaharsha vardhan vasa
hi lokesh thanks for the quick response. but i am getting error invalid constructor name. and after that i gave proper constructor and defined again     /////// public MyPageController(ApexPages.StandardController controller) {
this.controller = controller;
}////// and this time i am getting  error   as function already defined.  its not working :(
harsha vardhan vasaharsha vardhan vasa
sorry lokesh it worked.. i have tested it wrong my bad:)
Lokesh KumarLokesh Kumar
Cool ! Can you please mark it solved for others help in Future.

Happy to Help You
Lokesh